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
6ec25055
Commit
6ec25055
authored
9 years ago
by
Shirlei Chaves
Browse files
Options
Downloads
Patches
Plain Diff
Prevent election edit from using existing shortname
parent
eb5bb241
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
helios/migrations/0003_auto_20160507_1948.py
+20
-0
20 additions, 0 deletions
helios/migrations/0003_auto_20160507_1948.py
helios/models.py
+1
-1
1 addition, 1 deletion
helios/models.py
helios/views.py
+9
-12
9 additions, 12 deletions
helios/views.py
with
30 additions
and
13 deletions
helios/migrations/0003_auto_20160507_1948.py
0 → 100644
+
20
−
0
View file @
6ec25055
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
helios
'
,
'
0002_castvote_cast_ip
'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'
election
'
,
name
=
'
short_name
'
,
field
=
models
.
CharField
(
unique
=
True
,
max_length
=
100
),
preserve_default
=
True
,
),
]
This diff is collapsed.
Click to expand it.
helios/models.py
+
1
−
1
View file @
6ec25055
...
@@ -45,7 +45,7 @@ class Election(HeliosModel):
...
@@ -45,7 +45,7 @@ class Election(HeliosModel):
# later versions, at some point will upgrade to "2011/01/Election"
# later versions, at some point will upgrade to "2011/01/Election"
datatype
=
models
.
CharField
(
max_length
=
250
,
null
=
False
,
default
=
"
legacy/Election
"
)
datatype
=
models
.
CharField
(
max_length
=
250
,
null
=
False
,
default
=
"
legacy/Election
"
)
short_name
=
models
.
CharField
(
max_length
=
100
)
short_name
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
name
=
models
.
CharField
(
max_length
=
250
)
name
=
models
.
CharField
(
max_length
=
250
)
ELECTION_TYPES
=
(
ELECTION_TYPES
=
(
...
...
This diff is collapsed.
Click to expand it.
helios/views.py
+
9
−
12
View file @
6ec25055
...
@@ -10,7 +10,7 @@ from django.core.mail import send_mail
...
@@ -10,7 +10,7 @@ from django.core.mail import send_mail
from
django.core.paginator
import
Paginator
from
django.core.paginator
import
Paginator
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
from
django.http
import
*
from
django.http
import
*
from
django.db
import
transaction
from
django.db
import
transaction
,
IntegrityError
from
mimetypes
import
guess_type
from
mimetypes
import
guess_type
...
@@ -205,15 +205,11 @@ def election_new(request):
...
@@ -205,15 +205,11 @@ def election_new(request):
user
=
get_user
(
request
)
user
=
get_user
(
request
)
election_params
[
'
admin
'
]
=
user
election_params
[
'
admin
'
]
=
user
try
:
election
,
created_p
=
Election
.
get_or_create
(
**
election_params
)
election
=
Election
.
objects
.
create
(
**
election_params
)
if
created_p
:
# add Helios as a trustee by default
election
.
generate_trustee
(
ELGAMAL_PARAMS
)
election
.
generate_trustee
(
ELGAMAL_PARAMS
)
return
HttpResponseRedirect
(
settings
.
SECURE_URL_HOST
+
reverse
(
one_election_view
,
args
=
[
election
.
uuid
]))
return
HttpResponseRedirect
(
settings
.
SECURE_URL_HOST
+
reverse
(
one_election_view
,
args
=
[
election
.
uuid
]))
e
lse
:
e
xcept
IntegrityError
:
error
=
"
An election with short name %s already exists
"
%
election_params
[
'
short_name
'
]
error
=
"
An election with short name %s already exists
"
%
election_params
[
'
short_name
'
]
else
:
else
:
error
=
"
No special characters allowed in the short name.
"
error
=
"
No special characters allowed in the short name.
"
...
@@ -243,10 +239,11 @@ def one_election_edit(request, election):
...
@@ -243,10 +239,11 @@ def one_election_edit(request, election):
clean_data
=
election_form
.
cleaned_data
clean_data
=
election_form
.
cleaned_data
for
attr_name
in
RELEVANT_FIELDS
:
for
attr_name
in
RELEVANT_FIELDS
:
setattr
(
election
,
attr_name
,
clean_data
[
attr_name
])
setattr
(
election
,
attr_name
,
clean_data
[
attr_name
])
try
:
election
.
save
()
election
.
save
()
return
HttpResponseRedirect
(
settings
.
SECURE_URL_HOST
+
reverse
(
one_election_view
,
args
=
[
election
.
uuid
]))
return
HttpResponseRedirect
(
settings
.
SECURE_URL_HOST
+
reverse
(
one_election_view
,
args
=
[
election
.
uuid
]))
except
IntegrityError
:
error
=
"
An election with short name %s already exists
"
%
clean_data
[
'
short_name
'
]
return
render_template
(
request
,
"
election_edit
"
,
{
'
election_form
'
:
election_form
,
'
election
'
:
election
,
'
error
'
:
error
})
return
render_template
(
request
,
"
election_edit
"
,
{
'
election_form
'
:
election_form
,
'
election
'
:
election
,
'
error
'
:
error
})
...
...
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