Skip to content
Snippets Groups Projects
Commit 27d85617 authored by Ben Adida's avatar Ben Adida Committed by GitHub
Browse files

Merge pull request #149 from benadida/copy_election

add ability to copy an election
parents 5b3aff99 3623acd8
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ urlpatterns = patterns('',
(r'^/schedule$', one_election_schedule),
(r'^/extend$', one_election_extend),
(r'^/archive$', one_election_archive),
(r'^/copy$', one_election_copy),
# badge
(r'^/badge$', election_badge),
......
......@@ -10,7 +10,7 @@ from django.conf import settings
class ElectionForm(forms.Form):
short_name = forms.SlugField(max_length=25, help_text='no spaces, will be part of the URL for your election, e.g. my-club-2010')
short_name = forms.SlugField(max_length=40, help_text='no spaces, will be part of the URL for your election, e.g. my-club-2010')
name = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'size':60}), help_text='the pretty name for your election, e.g. My Club 2010 Election')
description = forms.CharField(max_length=4000, widget=forms.Textarea(attrs={'cols': 70, 'wrap': 'soft'}), required=False)
election_type = forms.ChoiceField(label="type", choices = Election.ELECTION_TYPES)
......
......@@ -15,6 +15,7 @@
{% endif %}
{% if admin_p %}
&nbsp;{% if election.is_archived %}<a class="small button" href="{% url "helios.views.one_election_archive" election_uuid=election.uuid %}?archive_p=0">unarchive it</a>{% else %}<a class="small button" href="{% url "helios.views.one_election_archive" election_uuid=election.uuid %}?archive_p=1">archive it</a>{% endif %}
<a class="small button" onclick="return window.confirm('Are you sure you want to copy this election?');" href="{% url "helios.views.one_election_copy" election_uuid=election.uuid %}">copy</a>
{% endif %}
<br />
{% if admin_p %}
......
......@@ -921,6 +921,40 @@ def one_election_archive(request, election):
return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(one_election_view, args=[election.uuid]))
@election_admin()
def one_election_copy(request, election):
# FIXME: make this a POST and CSRF protect it
# check_csrf(request)
# new short name by uuid, because it's easier and the user can change it.
new_uuid = uuid.uuid4()
new_short_name = new_uuid
new_election = Election.objects.create(
admin = election.admin,
uuid = new_uuid,
datatype = election.datatype,
short_name = new_short_name,
name = "Copy of " + election.name,
election_type = election.election_type,
private_p = election.private_p,
description = election.description,
questions = election.questions,
eligibility = election.eligibility,
openreg = election.openreg,
use_voter_aliases = election.use_voter_aliases,
use_advanced_audit_features = election.use_advanced_audit_features,
randomize_answer_order = election.randomize_answer_order,
registration_starts_at = election.registration_starts_at,
voting_starts_at = election.voting_starts_at,
voting_ends_at = election.voting_ends_at,
cast_url = settings.SECURE_URL_HOST + reverse(one_election_cast, args=[new_uuid])
)
new_election.generate_trustee(ELGAMAL_PARAMS)
return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(one_election_view, args=[new_election.uuid]))
# changed from admin to view because
# anyone can see the questions, the administration aspect is now
# built into the page
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment