From 7b6c43daae97e1f0c914a922940b72486386ca96 Mon Sep 17 00:00:00 2001 From: Virginia Dooley Date: Tue, 7 May 2024 08:58:15 +0100 Subject: [PATCH] Don't accept result values with . --- ynr/apps/uk_results/forms.py | 12 ++++++------ ynr/apps/uk_results/tests/test_smoke_test_views.py | 2 +- ynr/apps/utils/widgets.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ynr/apps/uk_results/forms.py b/ynr/apps/uk_results/forms.py index bda4d37a6..9f1d0d1a5 100644 --- a/ynr/apps/uk_results/forms.py +++ b/ynr/apps/uk_results/forms.py @@ -9,7 +9,7 @@ from django.db.models.functions import Coalesce from uk_results.helpers import RecordBallotResultsHelper from utils.db import LastWord, NullIfBlank -from utils.widgets import DCNumberInput +from utils.widgets import DCIntegerInput from .models import CandidateResult, ResultSet @@ -33,10 +33,10 @@ class Meta: "columns": 72, } ), - "num_turnout_reported": DCNumberInput(), - "turnout_percentage": DCNumberInput(), - "num_spoilt_ballots": DCNumberInput(), - "total_electorate": DCNumberInput(), + "num_turnout_reported": DCIntegerInput(), + "turnout_percentage": DCIntegerInput(), + "num_spoilt_ballots": DCIntegerInput(), + "total_electorate": DCIntegerInput(), } def __init__(self, ballot, *args, **kwargs): @@ -80,7 +80,7 @@ def __init__(self, ballot, *args, **kwargs): label=membership.name_and_party, initial=initial.get("num_ballots"), required=True, - widget=DCNumberInput, + widget=DCIntegerInput, ) fields[f"tied_vote_{name}"] = forms.BooleanField( required=False, diff --git a/ynr/apps/uk_results/tests/test_smoke_test_views.py b/ynr/apps/uk_results/tests/test_smoke_test_views.py index 5ae5ac0d4..c987d734d 100644 --- a/ynr/apps/uk_results/tests/test_smoke_test_views.py +++ b/ynr/apps/uk_results/tests/test_smoke_test_views.py @@ -49,7 +49,7 @@ def test_form_view_creates_result(self): resp = self.app.get(url, user=self.user_who_can_record_results) self.assertEqual(resp.status_code, 200) self.assertContains(resp, 'inputmode="numeric"') - self.assertContains(resp, r'pattern="[0-9\s\.,]*"') + self.assertContains(resp, r'pattern="[0-9\s,]*"') form = resp.forms[1] form["memberships_13"] = 1000 form["memberships_14"] = 2000 diff --git a/ynr/apps/utils/widgets.py b/ynr/apps/utils/widgets.py index 65f885661..508065b61 100644 --- a/ynr/apps/utils/widgets.py +++ b/ynr/apps/utils/widgets.py @@ -28,7 +28,7 @@ def create_option( return option -class DCNumberInput(TextInput): +class DCIntegerInput(TextInput): """ An input widget for entering numbers that isn't an input `type=number`. @@ -43,7 +43,7 @@ def build_attrs(self, base_attrs, extra_attrs=None): attrs.update( { "inputmode": "numeric", - "pattern": r"[0-9\s\.,]*", + "pattern": r"[0-9\s,]*", "oninvalid": "this.setCustomValidity('Enter a number')", } )