Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Helios Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Helios Server
Commits
95614ec3
Commit
95614ec3
authored
14 years ago
by
Ben Adida
Browse files
Options
Downloads
Patches
Plain Diff
added raw sql row locking to allow for alias generation on new voters
parent
a4ed1525
Branches
Branches containing commit
Tags
v3.0.9
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
helios/models.py
+12
-4
12 additions, 4 deletions
helios/models.py
helios/utils.py
+23
-0
23 additions, 0 deletions
helios/utils.py
with
35 additions
and
4 deletions
helios/models.py
+
12
−
4
View file @
95614ec3
...
@@ -6,7 +6,7 @@ Ben Adida
...
@@ -6,7 +6,7 @@ Ben Adida
(ben@adida.net)
(ben@adida.net)
"""
"""
from
django.db
import
models
from
django.db
import
models
,
transaction
from
django.utils
import
simplejson
from
django.utils
import
simplejson
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -156,7 +156,7 @@ class Election(models.Model, electionalgs.Election):
...
@@ -156,7 +156,7 @@ class Election(models.Model, electionalgs.Election):
"""
"""
expects a django uploaded_file data structure, which has filename, content, size...
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
=
VoterFile
(
election
=
self
)
new_voter_file
.
voter_file
.
save
(
random_filename
,
uploaded_file
)
new_voter_file
.
voter_file
.
save
(
random_filename
,
uploaded_file
)
self
.
append_log
(
ElectionLog
.
VOTER_FILE_ADDED
)
self
.
append_log
(
ElectionLog
.
VOTER_FILE_ADDED
)
...
@@ -344,7 +344,7 @@ class Election(models.Model, electionalgs.Election):
...
@@ -344,7 +344,7 @@ class Election(models.Model, electionalgs.Election):
# create the trustee
# create the trustee
trustee
=
Trustee
(
election
=
self
)
trustee
=
Trustee
(
election
=
self
)
trustee
.
uuid
=
str
(
uuid
.
uuid
1
())
trustee
.
uuid
=
str
(
uuid
.
uuid
4
())
trustee
.
name
=
settings
.
DEFAULT_FROM_NAME
trustee
.
name
=
settings
.
DEFAULT_FROM_NAME
trustee
.
email
=
settings
.
DEFAULT_FROM_EMAIL
trustee
.
email
=
settings
.
DEFAULT_FROM_EMAIL
trustee
.
public_key
=
keypair
.
pk
trustee
.
public_key
=
keypair
.
pk
...
@@ -470,7 +470,7 @@ class VoterFile(models.Model):
...
@@ -470,7 +470,7 @@ class VoterFile(models.Model):
# create the voter
# create the voter
if
not
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
=
Voter
(
uuid
=
voter_uuid
,
voter_type
=
'
password
'
,
voter_id
=
voter_id
,
name
=
name
,
election
=
election
)
voter_uuids
.
append
(
voter_uuid
)
voter_uuids
.
append
(
voter_uuid
)
voter
.
save
()
voter
.
save
()
...
@@ -508,9 +508,17 @@ class Voter(models.Model, electionalgs.Voter):
...
@@ -508,9 +508,17 @@ class Voter(models.Model, electionalgs.Voter):
cast_at
=
models
.
DateTimeField
(
auto_now_add
=
False
,
null
=
True
)
cast_at
=
models
.
DateTimeField
(
auto_now_add
=
False
,
null
=
True
)
@classmethod
@classmethod
@transaction.commit_on_success
def
register_user_in_election
(
cls
,
user
,
election
):
def
register_user_in_election
(
cls
,
user
,
election
):
voter_uuid
=
str
(
uuid
.
uuid4
())
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
)
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
()
voter
.
save
()
return
voter
return
voter
...
...
This diff is collapsed.
Click to expand it.
helios/utils.py
+
23
−
0
View file @
95614ec3
...
@@ -158,3 +158,26 @@ def send_email(sender, recpt_lst, subject, body):
...
@@ -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.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment