Skip to content

Commit

Permalink
Merge pull request #2321 from DemocracyClub/various-small-updates
Browse files Browse the repository at this point in the history
Various small updates
  • Loading branch information
symroe authored May 25, 2024
2 parents 3d799db + 7696652 commit f530568
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 115 deletions.
33 changes: 13 additions & 20 deletions ynr/apps/elections/uk/templates/candidates/_person_form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% csrf_token %}

<style>
label {
font-weight: bold;
}
</style>
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
Expand Down Expand Up @@ -90,6 +94,14 @@ <h2>Personal details:</h2>
{{ form.biography.errors }}
</div>

<div class="form-item {% if form.favourite_biscuit.errors %}form-item--errors{% endif %}">
<p>
{{ form.favourite_biscuit.label_tag }}
{{ form.favourite_biscuit }}
</p>
{{ form.favourite_biscuit.errors }}
</div>

<div class="form-item">
<h2>Candidacy:</h2>
{% if current_locked_ballots %}
Expand Down Expand Up @@ -218,25 +230,6 @@ <h2>Demographics:</h2>
{{ form.birth_date.errors }}
</div>

<div class="form-item {% if death_date.errors %}form-item--errors{% endif %}">
<p>
{{ form.death_date.label_tag }}
{{ form.death_date }}
</p>
{{ form.death_date.errors }}
</div>


<h2>Additional information:</h2>
<div class="form-item {% if form.favourite_biscuit.errors %}form-item--errors{% endif %}">
<p>
{{ form.favourite_biscuit.label_tag }}
{{ form.favourite_biscuit }}
</p>
{{ form.favourite_biscuit.errors }}
</div>


<div class="source-confirmation {% if form.source.errors %}source-confirmation--errors{% endif %}">
<p>
<label for="{{ form.source.id_for_label }}">
Expand Down
4 changes: 3 additions & 1 deletion ynr/apps/elections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def get_context_data(self, **kwargs):
filter=Q(membership__elected=True),
)
)
.order_by("election__election_date", "election__name")
.order_by(
"election__election_date", "election__name", "post__label"
)
)
f = CurrentOrFutureBallotFilter(self.request.GET, qs)

Expand Down
7 changes: 2 additions & 5 deletions ynr/apps/people/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from parties.models import Party
from people.forms.fields import (
CurrentUnlockedBallotsField,
PastOnlyBlankApproximateDateFormField,
StrippedCharField,
)
from people.helpers import (
Expand Down Expand Up @@ -269,6 +268,7 @@ class Meta:
"national_identity",
"name_search_vector",
"biography_last_updated",
"death_date",
)

honorific_prefix = StrippedCharField(
Expand All @@ -293,9 +293,6 @@ class Meta:
required=False,
widget=forms.NumberInput,
)
death_date = PastOnlyBlankApproximateDateFormField(
label="Date of death (a four digit year or a full date)", required=False
)

biography = StrippedCharField(
label="Statement to voters",
Expand All @@ -309,7 +306,7 @@ class Meta:
)

favourite_biscuit = StrippedCharField(
label="Favourite biscuit 🍪", required=False
label="Favourite biscuit 🍪", required=False, max_length=100
)

source = StrippedCharField(
Expand Down
2 changes: 0 additions & 2 deletions ynr/apps/people/tests/test_merge_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ def test_merging_people(self):

form = response.forms[1]
form["birth_date"] = "1962"
form["death_date"] = "2000"
form["source"] = "BBC News"
form.submit().follow()

Expand Down Expand Up @@ -677,7 +676,6 @@ def test_suggest_duplicate_people(self):

form = response.forms[1]
form["birth_date"] = "1962"
form["death_date"] = "2000"
form["source"] = "BBC News"
form.submit().follow()

Expand Down
87 changes: 0 additions & 87 deletions ynr/apps/people/tests/test_person_update.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from candidates.tests.factories import BallotPaperFactory, ElectionFactory
from candidates.views.version_data import get_change_metadata
from django.contrib.auth.models import User
Expand Down Expand Up @@ -40,44 +38,6 @@ def test_no_duplicate_versions(self):
self.person.record_version(get_change_metadata(None, "Nothing changed"))
self.assertEqual(len(self.person.versions), 2)

def test_set_death_date(self):
self.assertEqual(self.person.death_date, "")

response = self.app.get(
"/person/{}/update".format(self.person.pk), user=self.user
)

form = response.forms[1]
form["death_date"] = "2017-01-01"
form["source"] = "BBC News"
form.submit()

self.person.refresh_from_db()
self.assertEqual(self.person.death_date, "2017-01-01")

def test_set_death_date_different_formats(self):
date_formats = ["23 July 2019", "23/07/2019"]
for date_format in date_formats:
response = self.app.get(
"/person/{}/update".format(self.person.pk), user=self.user
)

form = response.forms[1]
form["death_date"] = date_format
form["source"] = "BBC News"
form.submit()

def test_set_death_date_too_long(self):
response = self.app.get(
"/person/{}/update".format(self.person.pk), user=self.user
)

form = response.forms[1]
form["death_date"] = ("a really really really long string",)
form["source"] = "BBC News"
response = form.submit()
self.assertContains(response, "Please enter a valid date.")

def test_set_birth_date_invalid_date(self):
"""
Regression for
Expand Down Expand Up @@ -110,52 +70,6 @@ def test_set_birth_date_year_only(self):
response = form.submit().follow()
self.assertContains(response, "1962")

def test_set_dead_person_age(self):
"""
Regression for
https://github.com/DemocracyClub/yournextrepresentative/issues/980
"""

response = self.app.get(
"/person/{}/update".format(self.person.pk), user=self.user
)

form = response.forms[1]
form["birth_date"] = "1962"
form["death_date"] = "2000"
form["source"] = "BBC News"
form.submit().follow()
self.person.refresh_from_db()
self.assertEqual(self.person.age, "37 or 38")

def test_validate_death_date_not_in_future(self):
response = self.app.get(
"/person/{}/update".format(self.person.pk), user=self.user
)

form = response.forms[1]
form["birth_date"] = "1962"
form["death_date"] = "2200"
form["source"] = "BBC News"
response = form.submit()
self.assertEqual(
response.context["form"].errors,
{"death_date": ["Can't enter a date in the future"]},
)

def test_validate_death_date_can_be_today(self):
response = self.app.get(
"/person/{}/update".format(self.person.pk), user=self.user
)
death_date = datetime.datetime.today().date().isoformat()
form = response.forms[1]
form["birth_date"] = "1962"
form["death_date"] = death_date
form["source"] = "BBC News"
form.submit().follow()
self.person.refresh_from_db()
self.assertEqual(self.person.death_date, death_date)

def test_user_cannot_review_person_name(self):
# current user is not in the TRUSTED_TO_EDIT_NAME group
# visit the moderation page and return a 403
Expand Down Expand Up @@ -348,7 +262,6 @@ def test_person_update_election_future_not_current(self):
"honorific_suffix",
"gender",
"birth_date",
"death_date",
"biography",
"favourite_biscuit",
"delisted",
Expand Down

0 comments on commit f530568

Please sign in to comment.