diff --git a/common/static/common/js/util.js b/common/static/common/js/util.js index e20012f51..e891ba133 100644 --- a/common/static/common/js/util.js +++ b/common/static/common/js/util.js @@ -7,7 +7,7 @@ const nodeListForEach = (nodes, callback) => { } } -const newLine = /\n/g; +const newLine = /[\n\r]/g; const removeNewLine = (str) => str.replace(newLine, "") const cleanResults = (results) => { diff --git a/measures/forms.py b/measures/forms.py index 0a17e6b10..c9ae7e85e 100644 --- a/measures/forms.py +++ b/measures/forms.py @@ -1148,7 +1148,9 @@ def clean(self): # Use quota order number origins and exclusions to set cleaned_data if self.order_number: - origins = self.order_number.quotaordernumberorigin_set.current() + origins = ( + self.order_number.quotaordernumberorigin_set.current().as_at_today_and_beyond() + ) cleaned_data["geo_areas_and_exclusions"] = [ { "geo_area": origin.geographical_area, diff --git a/measures/jinja2/measures/create-geo-areas-formset.jinja b/measures/jinja2/measures/create-geo-areas-formset.jinja index 5bbd1786c..99c5a33d6 100644 --- a/measures/jinja2/measures/create-geo-areas-formset.jinja +++ b/measures/jinja2/measures/create-geo-areas-formset.jinja @@ -3,12 +3,22 @@ {% from "components/summary-list/macro.njk" import govukSummaryList %} {% block breadcrumb %} - {% if request.path != "/" %} - {{ breadcrumbs(request, [{"text": "Review the geographical areas"}]) }} + {% if order_number %} + {% if request.path != "/" %} + {{ breadcrumbs(request, [{"text": "Review the geographical areas"}]) }} + {% endif %} + {% else %} + {{ super() }} {% endif %} - {% endblock %} +{% endblock %} -{% block page_title_heading %}Review the geographical areas{% endblock %} +{% block page_title_heading %} + {% if order_number %} + Review the geographical areas + {% else %} + {{ super() }} + {% endif %} +{% endblock %} {% block form %} {% if order_number and origins_and_exclusions %} diff --git a/measures/tests/test_forms.py b/measures/tests/test_forms.py index a518f1e71..ac3343734 100644 --- a/measures/tests/test_forms.py +++ b/measures/tests/test_forms.py @@ -471,18 +471,26 @@ def test_measure_forms_geo_area_invalid_data_error_messages(data, error, erga_om assert error in form.errors["geo_area"] -def test_measure_geographical_area_form_quota_order_number(): +def test_measure_geographical_area_form_quota_order_number(date_ranges): """Tests that `MeasureGeographicalAreaForm` sets `cleaned_data` with geographical data from quota order number if one is passed in `kwargs`.""" - origin_1 = factories.QuotaOrderNumberOriginFactory.create() - origin_2 = factories.QuotaOrderNumberOriginFactory.create( - order_number=origin_1.order_number, + old_origin = factories.QuotaOrderNumberOriginFactory.create( + valid_between=date_ranges.earlier, ) - origin_1_exclusions = factories.QuotaOrderNumberOriginExclusionFactory.create_batch( - 2, - origin=origin_1, + order_number = old_origin.order_number + + new_origin_1 = factories.QuotaOrderNumberOriginFactory.create( + order_number=order_number, + ) + new_origin_2 = factories.QuotaOrderNumberOriginFactory.create( + order_number=order_number, + ) + new_origin_1_exclusions = ( + factories.QuotaOrderNumberOriginExclusionFactory.create_batch( + 2, + origin=new_origin_1, + ) ) - order_number = origin_1.order_number with override_current_transaction(Transaction.objects.last()): form = forms.MeasureGeographicalAreaForm( @@ -495,11 +503,11 @@ def test_measure_geographical_area_form_quota_order_number(): expected_cleaned_data = [ { - "geo_area": origin_1.geographical_area, - "exclusions": list(origin_1.excluded_areas.all()), + "geo_area": new_origin_1.geographical_area, + "exclusions": list(new_origin_1.excluded_areas.all()), }, { - "geo_area": origin_2.geographical_area, + "geo_area": new_origin_2.geographical_area, "exclusions": [], }, ] diff --git a/requirements.txt b/requirements.txt index cd109a217..5a3798ba8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -39,7 +39,7 @@ elastic-apm==6.7.2 factory-boy==3.2.0 flower==1.2.0 freezegun==1.1.0 -gevent==21.12.0 +gevent==23.9.1 govuk-frontend-jinja @ git+https://github.com/alphagov/govuk-frontend-jinja.git@15845e4cca3a05df72c6e13ec6a7e35acc682f52 govuk-tech-docs-sphinx-theme==1.0.0 gunicorn==20.1.0