Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
shared
vote
Helios IFMA
Commits
95614ec3
Commit
95614ec3
authored
14 years ago
by
Ben Adida
Browse files
Options
Download
Email Patches
Plain Diff
added raw sql row locking to allow for alias generation on new voters
parent
a4ed1525
master
develop
master-ifnmg-bkp
upstream
v3.1.4
v3.1.3
v3.1.2
v3.1.1
v3.1.0
v3.0.16
v3.0.15
v3.0.14
v3.0.13
v3.0.12
v3.0.11
v3.0.10
v3.0.9
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
helios/models.py
+12
-4
helios/models.py
helios/utils.py
+23
-0
helios/utils.py
with
35 additions
and
4 deletions
+35
-4
helios/models.py
View file @
95614ec3
...
...
@@ -6,7 +6,7 @@ Ben Adida
(ben@adida.net)
"""
from
django.db
import
models
from
django.db
import
models
,
transaction
from
django.utils
import
simplejson
from
django.conf
import
settings
...
...
@@ -156,7 +156,7 @@ class Election(models.Model, electionalgs.Election):
"""
expects a django uploaded_file data structure, which has filename, content, size...
"""
random_filename
=
str
(
uuid
.
uuid
1
())
random_filename
=
str
(
uuid
.
uuid
4
())
new_voter_file
=
VoterFile
(
election
=
self
)
new_voter_file
.
voter_file
.
save
(
random_filename
,
uploaded_file
)
self
.
append_log
(
ElectionLog
.
VOTER_FILE_ADDED
)
...
...
@@ -344,7 +344,7 @@ class Election(models.Model, electionalgs.Election):
# create the trustee
trustee
=
Trustee
(
election
=
self
)
trustee
.
uuid
=
str
(
uuid
.
uuid
1
())
trustee
.
uuid
=
str
(
uuid
.
uuid
4
())
trustee
.
name
=
settings
.
DEFAULT_FROM_NAME
trustee
.
email
=
settings
.
DEFAULT_FROM_EMAIL
trustee
.
public_key
=
keypair
.
pk
...
...
@@ -470,7 +470,7 @@ class VoterFile(models.Model):
# create the voter
if
not
voter
:
voter_uuid
=
str
(
uuid
.
uuid
1
())
voter_uuid
=
str
(
uuid
.
uuid
4
())
voter
=
Voter
(
uuid
=
voter_uuid
,
voter_type
=
'password'
,
voter_id
=
voter_id
,
name
=
name
,
election
=
election
)
voter_uuids
.
append
(
voter_uuid
)
voter
.
save
()
...
...
@@ -508,9 +508,17 @@ class Voter(models.Model, electionalgs.Voter):
cast_at
=
models
.
DateTimeField
(
auto_now_add
=
False
,
null
=
True
)
@
classmethod
@
transaction
.
commit_on_success
def
register_user_in_election
(
cls
,
user
,
election
):
voter_uuid
=
str
(
uuid
.
uuid4
())
voter
=
Voter
(
uuid
=
voter_uuid
,
voter_type
=
user
.
user_type
,
voter_id
=
user
.
user_id
,
election
=
election
,
name
=
user
.
name
)
# do we need to generate an alias?
if
election
.
use_voter_aliases
:
heliosutils
.
lock_row
(
Election
,
election
.
id
)
alias_num
=
election
.
num_voters
+
1
voter
.
alias
=
"V%s"
%
alias_num
voter
.
save
()
return
voter
...
...
This diff is collapsed.
Click to expand it.
helios/utils.py
View file @
95614ec3
...
...
@@ -158,3 +158,26 @@ def send_email(sender, recpt_lst, subject, body):
##
## raw SQL and locking
##
def
lock_row
(
model
,
pk
):
"""
you almost certainly want to use lock_row inside a commit_on_success function
Eventually, in Django 1.2, this should move to the .for_update() support
"""
from
django.db
import
connection
,
transaction
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"select * from "
+
model
.
_meta
.
db_table
+
" where id = %s for update"
,
[
pk
])
row
=
cursor
.
fetchone
()
# if this is under transaction management control, mark the transaction dirty
try
:
transaction
.
set_dirty
()
except
:
pass
return
row
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help