diff --git a/additional_codes/jinja2/includes/additional_codes/tabs/measures.jinja b/additional_codes/jinja2/includes/additional_codes/tabs/measures.jinja index e029cc2c8..fa1a5421a 100644 --- a/additional_codes/jinja2/includes/additional_codes/tabs/measures.jinja +++ b/additional_codes/jinja2/includes/additional_codes/tabs/measures.jinja @@ -1,4 +1,4 @@ -{% from "components/sort_by.jinja" import sort_by %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% from "components/table/macro.njk" import govukTable %} {% set table_rows = [] %} @@ -37,4 +37,4 @@ {% endif %} {% include "includes/common/actions.jinja"%} - \ No newline at end of file + diff --git a/commodities/jinja2/includes/commodities/tabs/measures-declarable.jinja b/commodities/jinja2/includes/commodities/tabs/measures-declarable.jinja index e2e6f8a37..af98f8a09 100644 --- a/commodities/jinja2/includes/commodities/tabs/measures-declarable.jinja +++ b/commodities/jinja2/includes/commodities/tabs/measures-declarable.jinja @@ -1,5 +1,5 @@ {% extends "commodities/detail.jinja" %} -{% from "components/sort_by.jinja" import sort_by %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% set extra_tabs_links = [ { @@ -65,19 +65,19 @@ {% set base_url = url('commodity-ui-detail-measures-declarable', args=[commodity.sid]) %} {% set comm_code %} - {{ sort_by(request, "commodity", "Commodity code", base_url) }} + {{ create_sortable_anchor(request, "commodity", "Commodity code", base_url) }} {% endset %} {% set measure_type %} - {{ sort_by(request, "measure_type", "Measure type", base_url) }} + {{ create_sortable_anchor(request, "measure_type", "Measure type", base_url) }} {% endset %} {% set geo_area %} - {{ sort_by(request, "geo_area", "Geographical area", base_url) }} + {{ create_sortable_anchor(request, "geo_area", "Geographical area", base_url) }} {% endset %} {% set start_date %} - {{ sort_by(request, "start_date", "Start date", base_url) }} + {{ create_sortable_anchor(request, "start_date", "Start date", base_url) }} {% endset %} {% if paginator.count > 0 %} @@ -100,4 +100,4 @@ {% endif %} {% include "includes/common/pagination.jinja" %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/commodities/jinja2/includes/commodities/tabs/measures-defined.jinja b/commodities/jinja2/includes/commodities/tabs/measures-defined.jinja index 76eec8dff..b141df0be 100644 --- a/commodities/jinja2/includes/commodities/tabs/measures-defined.jinja +++ b/commodities/jinja2/includes/commodities/tabs/measures-defined.jinja @@ -1,5 +1,5 @@ {% extends "commodities/detail.jinja" %} -{% from "components/sort_by.jinja" import sort_by %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% set extra_tabs_links = [ { @@ -59,15 +59,15 @@ {% set base_url = url('commodity-ui-detail-measures-as-defined', args=[commodity.sid]) %} {% set measure_type %} - {{ sort_by(request, "measure_type", "Measure type", base_url) }} + {{ create_sortable_anchor(request, "measure_type", "Measure type", base_url) }} {% endset %} {% set geo_area %} - {{ sort_by(request, "geo_area", "Geographical area", base_url) }} + {{ create_sortable_anchor(request, "geo_area", "Geographical area", base_url) }} {% endset %} {% set start_date %} - {{ sort_by(request, "start_date", "Start date", base_url) }} + {{ create_sortable_anchor(request, "start_date", "Start date", base_url) }} {% endset %} {% if paginator.count > 0 %} @@ -89,4 +89,4 @@

There are no measures for this commodity code.

{% endif %} {% include "includes/common/pagination.jinja" %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/commodities/jinja2/includes/commodities/tabs/measures-vat-excise.jinja b/commodities/jinja2/includes/commodities/tabs/measures-vat-excise.jinja index 8f0fcb6e3..afe9458ca 100644 --- a/commodities/jinja2/includes/commodities/tabs/measures-vat-excise.jinja +++ b/commodities/jinja2/includes/commodities/tabs/measures-vat-excise.jinja @@ -1,5 +1,5 @@ {% extends "commodities/detail.jinja" %} -{% from "components/sort_by.jinja" import sort_by %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% set extra_tabs_links = [ { @@ -81,4 +81,4 @@

There are no VAT or excise measures for this commodity code.

{% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/commodities/tests/test_views.py b/commodities/tests/test_views.py index 9b70747fb..18534ec1f 100644 --- a/commodities/tests/test_views.py +++ b/commodities/tests/test_views.py @@ -245,7 +245,7 @@ def test_commodity_measures_sorting_geo_area( url_name, kwargs={"sid": commodity.sid}, ) - response = valid_user_client.get(f"{url}?sort_by=geo_area&order=desc") + response = valid_user_client.get(f"{url}?sort_by=geo_area&ordered=desc") assert response.status_code == 200 soup = BeautifulSoup(response.content.decode(response.charset), "html.parser") @@ -259,7 +259,7 @@ def test_commodity_measures_sorting_geo_area( "commodity-ui-detail-measures-as-defined", kwargs={"sid": commodity.sid}, ) - response = valid_user_client.get(f"{url}?sort_by=geo_area&order=asc") + response = valid_user_client.get(f"{url}?sort_by=geo_area&ordered=asc") assert response.status_code == 200 soup = BeautifulSoup(response.content.decode(response.charset), "html.parser") @@ -298,7 +298,7 @@ def test_commodity_measures_sorting_start_date( url_name, kwargs={"sid": commodity.sid}, ) - response = valid_user_client.get(f"{url}?sort_by=start_date&order=desc") + response = valid_user_client.get(f"{url}?sort_by=start_date&ordered=desc") assert response.status_code == 200 soup = BeautifulSoup(response.content.decode(response.charset), "html.parser") @@ -311,7 +311,7 @@ def test_commodity_measures_sorting_start_date( "commodity-ui-detail-measures-as-defined", kwargs={"sid": commodity.sid}, ) - response = valid_user_client.get(f"{url}?sort_by=start_date&order=asc") + response = valid_user_client.get(f"{url}?sort_by=start_date&ordered=asc") assert response.status_code == 200 soup = BeautifulSoup(response.content.decode(response.charset), "html.parser") @@ -353,7 +353,7 @@ def test_commodity_measures_sorting_measure_type( url_name, kwargs={"sid": commodity.sid}, ) - response = valid_user_client.get(f"{url}?sort_by=measure_type&order=desc") + response = valid_user_client.get(f"{url}?sort_by=measure_type&ordered=desc") assert response.status_code == 200 soup = BeautifulSoup(response.content.decode(response.charset), "html.parser") @@ -366,7 +366,7 @@ def test_commodity_measures_sorting_measure_type( "commodity-ui-detail-measures-as-defined", kwargs={"sid": commodity.sid}, ) - response = valid_user_client.get(f"{url}?sort_by=measure_type&order=asc") + response = valid_user_client.get(f"{url}?sort_by=measure_type&ordered=asc") assert response.status_code == 200 soup = BeautifulSoup(response.content.decode(response.charset), "html.parser") diff --git a/common/jinja2/components/create_sortable_anchor.jinja b/common/jinja2/components/create_sortable_anchor.jinja new file mode 100644 index 000000000..b83f591dc --- /dev/null +++ b/common/jinja2/components/create_sortable_anchor.jinja @@ -0,0 +1,21 @@ + +{% macro create_sortable_anchor(request, sort_by, title, base_url, query_params=False, fragment="") %} + + {% if query_params %} + {% set query_string_prefix = "&"%} + {% else %} + {% set query_string_prefix = "?"%} + {% endif %} + + {% if request.GET.sort_by == sort_by and request.GET.ordered == "desc" %} + + + {{ title }} + + {% else %} + + {{ title }} + + {% endif %} + +{% endmacro %} diff --git a/common/jinja2/components/sort_by.jinja b/common/jinja2/components/sort_by.jinja deleted file mode 100644 index cbbe100ef..000000000 --- a/common/jinja2/components/sort_by.jinja +++ /dev/null @@ -1,14 +0,0 @@ - -{% macro sort_by(request, sort_by, title, base_url, anchor="") %} - - {% if request.GET.sort_by == sort_by and request.GET.order == "desc" %} - - {{ title }} - - {% else %} - - {{ title }} - - {% endif %} - -{% endmacro %} \ No newline at end of file diff --git a/common/views.py b/common/views.py index 8b95c115d..e7f162bf4 100644 --- a/common/views.py +++ b/common/views.py @@ -435,7 +435,7 @@ def get_queryset(self): def get_ordering(self): sort_by = self.request.GET.get("sort_by") - order = self.request.GET.get("order") + ordered = self.request.GET.get("ordered") assert hasattr( self, "sort_by_fields", @@ -446,7 +446,7 @@ def get_ordering(self): if hasattr(self, "custom_sorting") and self.custom_sorting.get(sort_by): sort_by = self.custom_sorting.get(sort_by) - if order == "desc": + if ordered == "desc": sort_by = f"-{sort_by}" return sort_by diff --git a/geo_areas/jinja2/includes/geo_areas/tabs/measures.jinja b/geo_areas/jinja2/includes/geo_areas/tabs/measures.jinja index 708dd7310..4edd73849 100644 --- a/geo_areas/jinja2/includes/geo_areas/tabs/measures.jinja +++ b/geo_areas/jinja2/includes/geo_areas/tabs/measures.jinja @@ -1,6 +1,6 @@ {% extends "geo_areas/detail.jinja" %} -{% from "components/sort_by.jinja" import sort_by %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% from "components/table/macro.njk" import govukTable %} {% set actions_menu %} @@ -43,11 +43,11 @@ {% set base_url = url('geo_area-ui-detail-measures', kwargs={"sid": object.sid}) %} {% set commodity_code %} - {{ sort_by(request, "goods_nomenclature", "Commodity code", base_url) }} + {{ create_sortable_anchor(request, "goods_nomenclature", "Commodity code", base_url) }} {% endset %} {% set start_date %} - {{ sort_by(request, "start_date", "Start date", base_url) }} + {{ create_sortable_anchor(request, "start_date", "Start date", base_url) }} {% endset %} {% if paginator.count > 0 %} @@ -68,4 +68,4 @@

There are no measures for this regulation.

{% endif %} {% include "includes/common/pagination.jinja" %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/geo_areas/tests/test_views.py b/geo_areas/tests/test_views.py index 096f9d321..f4ca956de 100644 --- a/geo_areas/tests/test_views.py +++ b/geo_areas/tests/test_views.py @@ -585,7 +585,7 @@ def test_geo_area_detail_measures_view_sorting_commodity(valid_user_client): "sid": geo_area.sid, }, ) - response = valid_user_client.get(f"{url}?sort_by=goods_nomenclature&order=asc") + response = valid_user_client.get(f"{url}?sort_by=goods_nomenclature&ordered=asc") page = BeautifulSoup( response.content.decode(response.charset), "html.parser", @@ -596,7 +596,7 @@ def test_geo_area_detail_measures_view_sorting_commodity(valid_user_client): ] assert table_commodity_codes == commodity_codes - response = valid_user_client.get(f"{url}?sort_by=goods_nomenclature&order=desc") + response = valid_user_client.get(f"{url}?sort_by=goods_nomenclature&ordered=desc") page = BeautifulSoup( response.content.decode(response.charset), "html.parser", @@ -635,7 +635,7 @@ def test_geo_area_detail_measures_view_sorting_start_date( "sid": geo_area.sid, }, ) - response = valid_user_client.get(f"{url}?sort_by=start_date&order=asc") + response = valid_user_client.get(f"{url}?sort_by=start_date&ordered=asc") page = BeautifulSoup( response.content.decode(response.charset), "html.parser", @@ -645,7 +645,7 @@ def test_geo_area_detail_measures_view_sorting_start_date( ] assert table_measure_sids == [measure1.sid, measure2.sid, measure3.sid] - response = valid_user_client.get(f"{url}?sort_by=start_date&order=desc") + response = valid_user_client.get(f"{url}?sort_by=start_date&ordered=desc") page = BeautifulSoup( response.content.decode(response.charset), "html.parser", diff --git a/measures/jinja2/includes/measures/list.jinja b/measures/jinja2/includes/measures/list.jinja index 86062ad32..6997d94c9 100644 --- a/measures/jinja2/includes/measures/list.jinja +++ b/measures/jinja2/includes/measures/list.jinja @@ -2,8 +2,10 @@ {% from 'macros/footnotes_display.jinja' import footnotes_display %} {% from "includes/measures/conditions.jinja" import conditions_list %} {% from "components/button/macro.njk" import govukButton %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% from "components/warning-text/macro.njk" import govukWarningText %} + {# Sets out checkbox #} {% macro checkbox_item(field) -%} {% set id = field.id_for_label %} @@ -26,6 +28,26 @@
{%- endset %} +{% set sid %} + {{ create_sortable_anchor(request, "sid", "ID", base_url, query_params) }} +{% endset %} + +{% set measure_type %} + {{ create_sortable_anchor(request, "measure_type", "Type", base_url, query_params) }} +{% endset %} + +{% set geo_area %} + {{ create_sortable_anchor(request, "geo_area", "Geographical area", base_url, query_params) }} +{% endset %} + +{% set start_date %} + {{ create_sortable_anchor(request, "start_date", "Start date", base_url, query_params) }} +{% endset %} + +{% set end_date %} + {{ create_sortable_anchor(request, "end_date", "End date", base_url, query_params) }} +{% endset %} + {# sets out form #}
@@ -67,14 +89,14 @@ {{ govukTable({ "head": [ {"html": checkbox_check_all}, - {"text": "ID"}, - {"text": "Type"}, - {"text": "Commodity code"}, - {"text": "Start date"}, - {"text": "End date"}, + {"text": sid}, + {"text": measure_type}, + {"text": "Commodity"}, + {"text": start_date}, + {"text": end_date}, {"text": "Duties"}, {"text": "Additional code"}, - {"text": "Geographical area"}, + {"text": geo_area}, {"text": "Quota"}, {"text": "Footnote"}, {"text": "Conditions"}, diff --git a/measures/tests/test_views.py b/measures/tests/test_views.py index d1b9d9cfb..d92ecd0b3 100644 --- a/measures/tests/test_views.py +++ b/measures/tests/test_views.py @@ -26,6 +26,7 @@ from common.validators import UpdateType from common.views import TamatoListView from common.views import TrackedModelDetailMixin +from geo_areas.validators import AreaCode from measures.business_rules import ME70 from measures.constants import START from measures.constants import MeasureEditSteps @@ -2506,3 +2507,87 @@ def test_measure_list_redirects_to_search_with_no_params(valid_user_client): def test_measure_search_200(valid_user_client): response = valid_user_client.get(reverse("measure-ui-search")) assert response.status_code == 200 + + +def test_measures_list_sorting(valid_user_client, date_ranges): + # make measure types + type1 = factories.MeasureTypeFactory.create(sid="111") + type2 = factories.MeasureTypeFactory.create(sid="222") + type3 = factories.MeasureTypeFactory.create(sid="333") + + # Make geo_groups + # Erga Omnes + area_1 = factories.GeographicalAreaFactory.create( + area_code=AreaCode.GROUP, + area_id="1011", + ) + # North America + area_2 = factories.GeographicalAreaFactory.create( + area_code=AreaCode.GROUP, + area_id="2200", + ) + # European Union + area_3 = factories.GeographicalAreaFactory.create( + area_code=AreaCode.GROUP, + area_id="1013", + ) + + # make measures + measure1 = factories.MeasureFactory.create( + measure_type=type1, + geographical_area=area_2, + valid_between=date_ranges.no_end, + ) + measure2 = factories.MeasureFactory.create( + measure_type=type2, + geographical_area=area_3, + valid_between=date_ranges.earlier, + ) + measure3 = factories.MeasureFactory.create( + measure_type=type3, + geographical_area=area_1, + valid_between=date_ranges.later, + ) + + sort_by_list = [ + "?sort_by=sid&ordered=desc", + "?sort_by=sid&ordered=asc", + "?sort_by=measure_type&ordered=desc", + "?sort_by=measure_type&ordered=asc", + "?sort_by=start_date&ordered=desc", + "?sort_by=start_date&ordered=asc", + "?sort_by=end_date&ordered=desc", + "?sort_by=end_date&ordered=asc", + "?sort_by=geo_area&ordered=desc", + "?sort_by=geo_area&ordered=asc", + ] + + expected_order_list = [ + # sid desc, asc + [measure3.sid, measure2.sid, measure1.sid], + [measure1.sid, measure2.sid, measure3.sid], + # type desc, asc + [measure3.sid, measure2.sid, measure1.sid], + [measure1.sid, measure2.sid, measure3.sid], + # start date desc, asc + [measure3.sid, measure1.sid, measure2.sid], + [measure2.sid, measure1.sid, measure3.sid], + # end date desc, asc + [measure1.sid, measure3.sid, measure2.sid], + [measure2.sid, measure3.sid, measure1.sid], + # geo area desc, asc + [measure1.sid, measure2.sid, measure3.sid], + [measure3.sid, measure2.sid, measure1.sid], + ] + + for index, item in enumerate(sort_by_list): + url = reverse("measure-ui-list") + item + response = valid_user_client.get(url) + + assert response.status_code == 200 + + soup = BeautifulSoup(response.content.decode(response.charset), "html.parser") + measure_sids = [ + int(el.text) for el in soup.select(".govuk-table tbody tr td:nth-child(2)") + ] + assert measure_sids == expected_order_list[index] diff --git a/measures/views.py b/measures/views.py index 15d655b39..577ad05a5 100644 --- a/measures/views.py +++ b/measures/views.py @@ -32,6 +32,7 @@ from common.serializers import AutoCompleteSerializer from common.util import TaricDateRange from common.validators import UpdateType +from common.views import SortingMixin from common.views import TamatoListView from common.views import TrackedModelDetailMixin from common.views import TrackedModelDetailView @@ -133,24 +134,61 @@ def form_valid(self, form): return HttpResponseRedirect(reverse("measure-ui-list")) -class MeasureList(MeasureSelectionMixin, MeasureMixin, FormView, TamatoListView): +class MeasureList( + MeasureSelectionMixin, + MeasureMixin, + SortingMixin, + FormView, + TamatoListView, +): """UI endpoint for viewing and filtering Measures.""" template_name = "measures/list.jinja" filterset_class = MeasureFilter form_class = SelectableObjectsForm + sort_by_fields = ["sid", "measure_type", "geo_area", "start_date", "end_date"] + custom_sorting = { + "measure_type": "measure_type__sid", + "geo_area": "geographical_area__area_id", + "start_date": "valid_between", + "end_date": "db_effective_end_date", + } def dispatch(self, *args, **kwargs): if not self.request.GET: return HttpResponseRedirect(reverse("measure-ui-search")) return super().dispatch(*args, **kwargs) + def get_queryset(self): + queryset = super().get_queryset() + + ordering = self.get_ordering() + + if ordering: + if ordering in "-db_effective_end_date": + queryset = queryset.with_effective_valid_between() + + ordering = (ordering,) + queryset = queryset.order_by(*ordering) + + return queryset + def get_form_kwargs(self): kwargs = super().get_form_kwargs() page = self.paginator.get_page(self.request.GET.get("page", 1)) kwargs["objects"] = page.object_list return kwargs + def cleaned_query_params(self): + # Remove the sort_by and ordered params in order to stop them being duplicated in the base url + if "sort_by" and "ordered" in self.filterset.data: + cleaned_filterset = self.filterset.data.copy() + cleaned_filterset.pop("sort_by") + cleaned_filterset.pop("ordered") + return cleaned_filterset + else: + return self.filterset.data + @property def paginator(self): filterset_class = self.get_filterset_class() @@ -195,6 +233,10 @@ def get_context_data(self, **kwargs): context["measure_selections"] = Measure.objects.filter( pk__in=measure_selections, ) + context["query_params"] = True + context[ + "base_url" + ] = f'{reverse("measure-ui-list")}?{urlencode(self.cleaned_query_params())}' return context def get_initial(self): diff --git a/quotas/jinja2/includes/quotas/tabs/measures.jinja b/quotas/jinja2/includes/quotas/tabs/measures.jinja index 2ac71c2ac..7798c56df 100644 --- a/quotas/jinja2/includes/quotas/tabs/measures.jinja +++ b/quotas/jinja2/includes/quotas/tabs/measures.jinja @@ -1,4 +1,4 @@ -{% from "components/sort_by.jinja" import sort_by %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% set table_rows = [] %} {% for object in measures %} @@ -19,7 +19,7 @@ {% set base_url = url('quota-ui-detail', args=[object.sid]) %} {% set commodity_code %} - {{ sort_by(request, "goods_nomenclature", "Commodity code", base_url, "#measures") }} + {{ create_sortable_anchor(request, "goods_nomenclature", "Commodity code", base_url, "#measures") }} {% endset %}
@@ -41,4 +41,4 @@ {% endif %}
{% include "includes/quotas/actions.jinja"%} - \ No newline at end of file + diff --git a/quotas/jinja2/quotas/definitions.jinja b/quotas/jinja2/quotas/definitions.jinja index 2c27fd13b..803ff6fa7 100644 --- a/quotas/jinja2/quotas/definitions.jinja +++ b/quotas/jinja2/quotas/definitions.jinja @@ -4,7 +4,7 @@ {% from "components/table/macro.njk" import govukTable %} {% from "components/details/macro.njk" import govukDetails %} {% from "components/summary-list/macro.njk" import govukSummaryList %} -{% from "components/sort_by.jinja" import sort_by %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% set page_title = "Quota ID: " ~ quota.order_number ~ " - Data" %} {% set find_edit_url = url("quota-ui-list") %} @@ -46,4 +46,4 @@ {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/quotas/jinja2/quotas/tables/definitions.jinja b/quotas/jinja2/quotas/tables/definitions.jinja index de7310835..b9f1bac9e 100644 --- a/quotas/jinja2/quotas/tables/definitions.jinja +++ b/quotas/jinja2/quotas/tables/definitions.jinja @@ -65,11 +65,11 @@ {% endfor %} {% set sid %} - {{ sort_by(request, "sid", "Quota definition sid", base_url) }} + {{ create_sortable_anchor(request, "sid", "Quota definition sid", base_url) }} {% endset %} {% set start_date %} - {{ sort_by(request, "valid_between", "Start date", base_url) }} + {{ create_sortable_anchor(request, "valid_between", "Start date", base_url) }} {% endset %} {{ govukTable({ @@ -85,4 +85,4 @@ {"text": "Actions"}, ], "rows": table_rows -}) }} \ No newline at end of file +}) }} diff --git a/quotas/tests/test_views.py b/quotas/tests/test_views.py index 21ab32a82..c301c3503 100644 --- a/quotas/tests/test_views.py +++ b/quotas/tests/test_views.py @@ -565,7 +565,7 @@ def test_quota_definitions_list_sort_by_start_date( ) url = reverse("quota-definitions", kwargs={"sid": quota_order_number.sid}) - response = valid_user_client.get(f"{url}?sort_by=valid_between&order=asc") + response = valid_user_client.get(f"{url}?sort_by=valid_between&ordered=asc") assert response.status_code == 200 page = BeautifulSoup(response.content.decode(response.charset), "html.parser") definition_sids = [ @@ -574,7 +574,7 @@ def test_quota_definitions_list_sort_by_start_date( ] assert definition_sids == [definition1.sid, definition2.sid] - response = valid_user_client.get(f"{url}?sort_by=valid_between&order=desc") + response = valid_user_client.get(f"{url}?sort_by=valid_between&ordered=desc") assert response.status_code == 200 page = BeautifulSoup(response.content.decode(response.charset), "html.parser") definition_sids = [ diff --git a/regulations/jinja2/includes/regulations/tabs/measures.jinja b/regulations/jinja2/includes/regulations/tabs/measures.jinja index c4777f727..00f24c85a 100644 --- a/regulations/jinja2/includes/regulations/tabs/measures.jinja +++ b/regulations/jinja2/includes/regulations/tabs/measures.jinja @@ -1,6 +1,6 @@ {% extends "regulations/detail.jinja" %} -{% from "components/sort_by.jinja" import sort_by %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% from "components/table/macro.njk" import govukTable %} {% set actions_menu %} @@ -48,15 +48,15 @@ {% set base_url = url('regulation-ui-detail-measures', kwargs={"role_type": object.role_type, "regulation_id": object.regulation_id}) %} {% set commodity_code %} - {{ sort_by(request, "goods_nomenclature", "Commodity code", base_url) }} + {{ create_sortable_anchor(request, "goods_nomenclature", "Commodity code", base_url) }} {% endset %} {% set geo_area %} - {{ sort_by(request, "geo_area", "Geographical area", base_url) }} + {{ create_sortable_anchor(request, "geo_area", "Geographical area", base_url) }} {% endset %} {% set start_date %} - {{ sort_by(request, "start_date", "Start date", base_url) }} + {{ create_sortable_anchor(request, "start_date", "Start date", base_url) }} {% endset %} {% if paginator.count > 0 %} diff --git a/regulations/tests/test_views.py b/regulations/tests/test_views.py index 80f325895..be4652d56 100644 --- a/regulations/tests/test_views.py +++ b/regulations/tests/test_views.py @@ -157,7 +157,7 @@ def test_regulation_detail_measures_view_sorting_commodity(valid_user_client): "regulation_id": regulation.regulation_id, }, ) - response = valid_user_client.get(f"{url}?sort_by=goods_nomenclature&order=asc") + response = valid_user_client.get(f"{url}?sort_by=goods_nomenclature&ordered=asc") page = BeautifulSoup( response.content.decode(response.charset), "html.parser", @@ -168,7 +168,7 @@ def test_regulation_detail_measures_view_sorting_commodity(valid_user_client): ] assert table_commodity_codes == commodity_codes - response = valid_user_client.get(f"{url}?sort_by=goods_nomenclature&order=desc") + response = valid_user_client.get(f"{url}?sort_by=goods_nomenclature&ordered=desc") page = BeautifulSoup( response.content.decode(response.charset), "html.parser", @@ -208,7 +208,7 @@ def test_regulation_detail_measures_view_sorting_start_date( "regulation_id": regulation.regulation_id, }, ) - response = valid_user_client.get(f"{url}?sort_by=start_date&order=asc") + response = valid_user_client.get(f"{url}?sort_by=start_date&ordered=asc") page = BeautifulSoup( response.content.decode(response.charset), "html.parser", @@ -218,7 +218,7 @@ def test_regulation_detail_measures_view_sorting_start_date( ] assert table_measure_sids == [measure1.sid, measure2.sid, measure3.sid] - response = valid_user_client.get(f"{url}?sort_by=start_date&order=desc") + response = valid_user_client.get(f"{url}?sort_by=start_date&ordered=desc") page = BeautifulSoup( response.content.decode(response.charset), "html.parser", diff --git a/workbaskets/jinja2/workbaskets/violations.jinja b/workbaskets/jinja2/workbaskets/violations.jinja index 1f057ac4e..8781a41f0 100644 --- a/workbaskets/jinja2/workbaskets/violations.jinja +++ b/workbaskets/jinja2/workbaskets/violations.jinja @@ -2,7 +2,7 @@ {% from "components/breadcrumbs/macro.njk" import govukBreadcrumbs %} {% from "components/table/macro.njk" import govukTable %} -{% from "components/sort_by.jinja" import sort_by %} +{% from "components/create_sortable_anchor.jinja" import create_sortable_anchor %} {% from "includes/workbaskets/navigation.jinja" import navigation %} {% set page_title %}Workbasket {{ workbasket.id if workbasket else request.session.workbasket.id }} - Rule violations {% endset %} @@ -35,15 +35,15 @@ {% set base_url = url('workbaskets:workbasket-ui-violations' ) %} {% set item %} - {{ sort_by(request, "model", "Item", base_url) }} + {{ create_sortable_anchor(request, "model", "Item", base_url) }} {% endset %} {% set violation %} - {{ sort_by(request, "check_name", "Violation", base_url) }} + {{ create_sortable_anchor(request, "check_name", "Violation", base_url) }} {% endset %} {% set activity_date %} - {{ sort_by(request, "date", "Activity date", base_url) }} + {{ create_sortable_anchor(request, "date", "Activity date", base_url) }} {% endset %} {{ govukTable({ @@ -56,4 +56,4 @@ ], "rows": table_rows }) }} -{% endblock %} \ No newline at end of file +{% endblock %}