Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Add candidacy wizard: make historic elections an option #969

Merged
merged 2 commits into from
Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions candidates/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,13 @@ class Meta:

class AddCandidacyPickElectionForm(forms.Form):

election = forms.ModelChoiceField(
queryset=Election.objects.order_by('-election_date', 'name'))
def __init__(self, *args, **kwargs):
include_historic = kwargs.pop('include_historic')
super(AddCandidacyPickElectionForm, self).__init__(*args, **kwargs)
election_qs = Election.objects.order_by('-election_date', 'name')
if not include_historic:
election_qs = election_qs.filter(current=True)
self.fields['election'] = forms.ModelChoiceField(queryset=election_qs)

def clean_election(self):
election = self.cleaned_data['election']
Expand Down
3 changes: 2 additions & 1 deletion candidates/templates/candidates/_person_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ <h3>{{ constituency_fields.election_name }}</h3>
{% endfor %}

{% if not add_candidate_form %}
<h2>{% trans "Add a candidacy in another election" %}</h2>
<div class="add-candidacy-link">
<a href="{% url 'person-update-add-candidacy' person_id=person.id %}">
{% trans "Add a candidacy in an election" %}
{% trans "Add a new candidacy" %}
</a>
</div>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ <h3>{% trans "Choose the election to which you're adding a candidacy" %}</h3>
{% block candidacy_wizard_submit %}
<input type="submit" class="button pick-election"
value="{% trans "Select" context "On the submit button to select an election to add a candidacy for." %}" />
{% if not include_historic %}
<p>Or there's <a href="?historic=1">another form if you need to add a candidacy for a historic election.</a></p>
{% endif %}
{% endblock %}

{% block extra_js %}
Expand Down
33 changes: 33 additions & 0 deletions candidates/tests/test_add_candidacy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

import re

from django.core.urlresolvers import reverse
from django.utils.six import text_type
Expand Down Expand Up @@ -228,3 +229,35 @@ def test_all_steps_with_party_list_position_successful(self):
person=self.person,
role='Candidate')
self.assertEqual(m.extra.party_list_position, 3)

def test_election_pick_historic_link_present(self):
response = self.app.get(self.wizard_url, user=self.user)
link = response.html.find(
'a',
text=re.compile(r'add a candidacy for a historic election'))
self.assertTrue(link)

def test_election_pick_historic_link_not_present(self):
url = self.wizard_url + '?historic=1'
response = self.app.get(url, user=self.user)
link = response.html.find(
'a',
text=re.compile(r'add a candidacy for a historic election'))
self.assertFalse(link)

def test_election_pick_only_current_by_default(self):
response = self.app.get(self.wizard_url, user=self.user)
election_form = response.forms['add-candidacy-wizard']
election_field = election_form['election-election']
self.assertEqual(
[t[2] for t in election_field.options],
['---------', '2015 General Election'])

def test_election_all_elections_with_historic_parameter(self):
url = self.wizard_url + '?historic=1'
response = self.app.get(url, user=self.user)
election_form = response.forms['add-candidacy-wizard']
election_field = election_form['election-election']
self.assertEqual(
[t[2] for t in election_field.options],
['---------', '2015 General Election', '2010 General Election'])
4 changes: 3 additions & 1 deletion candidates/views/candidacies.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def get_post_slug(self):
def get_form_kwargs(self, step=None):
kwargs = super(AddCandidacyWizardView, self).get_form_kwargs(step)
if step == 'election':
return kwargs
include_historic = self.request.GET.get('historic') == '1'
kwargs['include_historic'] = include_historic
elif step == 'post':
cleaned_data = self.get_cleaned_data_for_step('election')
kwargs['election'] = cleaned_data['election']
Expand All @@ -198,6 +199,7 @@ def get_form_kwargs(self, step=None):
def get_context_data(self, form, **kwargs):
context = super(AddCandidacyWizardView, self).get_context_data(form, **kwargs)
context['person'] = self.person
context['include_historic'] = (self.request.GET.get('historic') == '1')
return context

def done(self, form_list, **kwargs):
Expand Down
82 changes: 81 additions & 1 deletion locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,26 @@ msgstr ""
msgid "Please indicate how you know that this is a valid alternative name"
msgstr ""

#: candidates/management/commands/candidates_create_areas_and_posts_from_mapit.py:50
#: candidates/forms.py:577
#, python-brace-format
msgid "No posts have been created for the {election_name}"
msgstr ""

#: candidates/forms.py:582
#, python-brace-format
msgid "There are no unlocked posts in the election {election_name} - if you think the candidates for this election are wrong or incomplete, please <a href=\"mailto:{support_email}\">contact us</a>."
msgstr ""

#: candidates/forms.py:598
#, python-format
msgid "Post in %s"
msgstr ""

#: candidates/forms.py:649
msgid "You must specify a party"
msgstr ""

#: candidates/management/commands/candidates_create_areas_and_posts_from_mapit.py:55
#, python-brace-format
msgid "{post_role} for {area_name}"
msgstr ""
Expand Down Expand Up @@ -753,6 +772,14 @@ msgid "Candidacy:"
msgstr ""

#: candidates/templates/candidates/_person_form.html:99
msgid "Add a candidacy in another election"
msgstr ""

#: candidates/templates/candidates/_person_form.html:102
msgid "Add a new candidacy"
msgstr ""

#: candidates/templates/candidates/_person_form.html:109
#: candidates/templates/candidates/person-view.html:171
msgid "Links and social media:"
msgstr ""
Expand Down Expand Up @@ -1551,6 +1578,59 @@ msgstr ""
msgid "Please make sure you read our <a href=\"https://docs.google.com/document/d/1iA5Tv3ZgjDHWNv6gbNESqL-C7Goz6ZSo1X9pPXwXspA/edit\">guidance on sourcing fields</a>."
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-pick-election.html:5
#, python-format
msgid "Picking a new election for: %(name)s"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-pick-election.html:8
msgid "Choose the election to which you're adding a candidacy"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-pick-election.html:13
msgctxt "On the submit button to select an election to add a candidacy for."
msgid "Select"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-pick-party.html:5
#: candidates/templates/candidates/person-edit-candidacy-source.html:5
#, python-format
msgid "Picking a new party for %(name)s, standing for %(post)s in %(election)s"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-pick-party.html:8
msgid "Choose the party they're standing for:"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-pick-party.html:13
msgctxt "On the submit button to select a party of someone you're add a candidacy for."
msgid "Select"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-pick-post.html:5
#, python-format
msgid "Picking a new post in %(election)s for: %(name)s"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-pick-post.html:8
msgid "Choose the post for which you're adding a candidacy"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-pick-post.html:13
msgctxt "On the submit button to select a post to add a candidacy for."
msgid "Select"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-source.html:8
msgid "Enter the source of that information"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-source.html:13
msgctxt "On the submit button to enter the information source of someone you're adding a candidacy for."
msgid "Add Candidacy"
msgstr ""

#: candidates/templates/candidates/person-edit-candidacy-wizard.html:22
#: candidates/templates/candidates/person-edit.html:9
#: candidates/templates/candidates/person-edit.html:27
#, python-format
Expand Down