Skip to content

Commit

Permalink
Merge branch 'master' into TP2000-1471--task-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dalecannon committed Oct 29, 2024
2 parents 9faac8b + 40ab16a commit 0595097
Show file tree
Hide file tree
Showing 65 changed files with 3,933 additions and 486 deletions.
1 change: 1 addition & 0 deletions .copilot/image_build_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
set -e

# Add commands below to run inside the container after all the other buildpacks have been applied
python manage.py collectstatic --noinput --clear
20 changes: 0 additions & 20 deletions .profile

This file was deleted.

10 changes: 8 additions & 2 deletions commodities/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from commodities.models.orm import GoodsNomenclature
from common.filters import ActiveStateMixin
from common.filters import CurrentWorkBasketMixin
from common.filters import EndDateMixin
from common.filters import TamatoFilter
from common.filters import TamatoFilterBackend
from common.validators import AlphanumericValidator
Expand All @@ -33,9 +34,14 @@ def search_queryset(self, queryset, search_term):
return super().search_queryset(queryset, search_term)


class CommodityFilter(ActiveStateMixin, TamatoFilter, CurrentWorkBasketMixin):
class CommodityFilter(
ActiveStateMixin,
TamatoFilter,
CurrentWorkBasketMixin,
EndDateMixin,
):
item_id = CharFilter(
label="Code",
label="Commodity code",
widget=forms.TextInput(),
lookup_expr="startswith",
validators=[NumericValidator],
Expand Down
19 changes: 16 additions & 3 deletions commodities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,28 @@ def __init__(self, *args, **kwargs):
self.helper.layout = Layout(
Field.text("item_id", label_size=Size.SMALL),
Field.text("descriptions__description", label_size=Size.SMALL),
Field.text("active_state", label_size=Size.SMALL),
Field.checkboxes(
"active_state",
legend_size=Size.SMALL,
),
Fieldset(
Field.text("with_footnotes", label_size=Size.SMALL),
legend="Footnotes",
legend_size=Size.SMALL,
),
Fieldset(
Field.text("with_end_date", label_size=Size.SMALL),
legend="End date",
legend_size=Size.SMALL,
),
Fieldset(
Field.text("current_work_basket", label_size=Size.SMALL),
legend="Workbasket",
legend_size=Size.SMALL,
),
Field.text("current_work_basket", label_size=Size.SMALL),
Button(
"submit",
"Search and Filter",
"Search and filter",
),
HTML(
f'<a class="govuk-button govuk-button--secondary" href="{self.clear_url}"> Clear </a>',
Expand Down
4 changes: 4 additions & 0 deletions commodities/jinja2/includes/commodities/table.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
{"text": commodity.suffix},
{"text": commodity.get_indent_as_at(today).indent},
{"text": commodity.get_description().description},
{"text": "{:%d %b %Y}".format(commodity.valid_between.lower)},
{"text": "{:%d %b %Y}".format(commodity.valid_between.upper) if commodity.valid_between.upper else "-"},
{"text": commodity_footnotes},
]) or "" }}
{% endfor %}
Expand All @@ -24,6 +26,8 @@
{"text": "Suffix"},
{"text": "Indent"},
{"text": "Commodity description"},
{"text": "Start date"},
{"text": "End date"},
{"text": "Footnotes"},

],
Expand Down
16 changes: 16 additions & 0 deletions commodities/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

def test_commodity_list_displays_commodity_suffix_indent_and_description(
valid_user_client,
date_ranges,
):
"""Test that a list of commodity codes with links and their suffixes,
indents and descriptions are displayed on the list view template."""
Expand All @@ -37,6 +38,9 @@ def test_commodity_list_displays_commodity_suffix_indent_and_description(
description="A second commodity code description",
).described_goods_nomenclature

commodity2.valid_between = date_ranges.normal
commodity2.save(force_write=True)

url = reverse("commodity-ui-list")
response = valid_user_client.get(url)
page = BeautifulSoup(
Expand All @@ -51,6 +55,10 @@ def test_commodity_list_displays_commodity_suffix_indent_and_description(
text=commodity1.get_indent_as_at(datetime.date.today()).indent,
)
assert page.find("tbody").find("td", text="A commodity code description")
assert page.find("tbody").find(
"td",
text=f"{commodity1.valid_between.lower:%d %b %Y}",
)

assert page.find("tbody").find("td", text=commodity2.item_id)
assert page.find("tbody").find(href=f"/commodities/{commodity2.sid}/")
Expand All @@ -60,6 +68,14 @@ def test_commodity_list_displays_commodity_suffix_indent_and_description(
text=commodity2.get_indent_as_at(datetime.date.today()).indent,
)
assert page.find("tbody").find("td", text="A second commodity code description")
assert page.find("tbody").find(
"td",
text=f"{commodity2.valid_between.lower:%d %b %Y}",
)
assert page.find("tbody").find(
"td",
text=f"{commodity2.valid_between.upper:%d %b %Y}",
)


def test_commodity_list_queryset():
Expand Down
18 changes: 17 additions & 1 deletion common/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class ActiveStateMixin(FilterSet):
widget=forms.CheckboxSelectMultiple,
method="filter_active_state",
label="Active state",
help_text="Select all that apply",
help_text="Select one to filter by active or terminated items",
required=False,
)

Expand Down Expand Up @@ -348,3 +348,19 @@ def filter_work_basket(self, queryset, name, value):
id__in=wanted_objects_id,
)
return queryset


class EndDateMixin(FilterSet):
"""A filter to only show objects which have an end date."""

with_end_date = BooleanFilter(
label="Show items with an end date",
widget=forms.CheckboxInput(),
method="filter_end_date",
required=False,
)

def filter_end_date(self, queryset, name, value):
if value:
queryset = queryset.filter(valid_between__upper_inf=False)
return queryset
51 changes: 45 additions & 6 deletions common/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

from crispy_forms_gds.fields import DateInputField
from crispy_forms_gds.helper import FormHelper
from crispy_forms_gds.layout import HTML
from crispy_forms_gds.layout import Div
from crispy_forms_gds.layout import Field
from crispy_forms_gds.layout import Layout
from crispy_forms_gds.layout import Size
from crispy_forms_gds.layout import Submit
from django import forms
from django.contrib.postgres.forms.ranges import DateRangeField
from django.core.exceptions import NON_FIELD_ERRORS
from django.core.exceptions import ValidationError
from django.forms.renderers import get_default_renderer
from django.forms.utils import ErrorList
Expand Down Expand Up @@ -457,12 +459,18 @@ def __init__(self, *args, **kwargs):
self.helper.label_size = Size.SMALL
self.helper.legend_size = Size.SMALL
self.helper.layout = Layout(
Submit(
"submit",
"Delete",
css_class="govuk-button--warning",
data_module="govuk-button",
data_prevent_double_click="true",
Div(
Submit(
"submit",
"Delete",
css_class="govuk-button--warning",
data_module="govuk-button",
data_prevent_double_click="true",
),
HTML(
f"<a class='govuk-button govuk-button--secondary' href={self.instance.get_url()}>Cancel</a>",
),
css_class="govuk-button-group",
),
)

Expand Down Expand Up @@ -892,3 +900,34 @@ def deserialize_init_kwargs(cls, form_kwargs: Dict) -> Dict:
representation.
"""
return {}


class ExtraErrorFormMixin:
def add_extra_error(self, field, error):
"""
A modification of Django's add_error method that allows us to add data
to self._errors under custom keys that are not field names or
NON_FIELD_ERRORS.
Used to pass errors to the React form.
"""
if not isinstance(error, ValidationError):
error = ValidationError(error)

if hasattr(error, "error_dict"):
if field is not None:
raise TypeError(
"The argument `field` must be `None` when the `error` "
"argument contains errors for multiple fields.",
)
else:
error = error.error_dict
else:
error = {field or NON_FIELD_ERRORS: error.error_list}

for field, error_list in error.items():
if field not in self.errors:
self._errors[field] = self.error_class()
self._errors[field].extend(error_list)
if field in self.cleaned_data:
del self.cleaned_data[field]
6 changes: 0 additions & 6 deletions common/jinja2/common/delete.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,4 @@
{% call django_form(action=object.get_url("delete")) %}
{{ crispy(form) }}
{% endcall %}

{{ govukButton({
"text": "Cancel",
"href": object.get_url(),
"classes": "govuk-button--secondary"
}) }}
{% endblock %}
10 changes: 3 additions & 7 deletions common/jinja2/layouts/create.jinja
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{% extends 'layouts/form.jinja' %}

{% block form %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{% call django_form() %}
{{ crispy(form) }}
{% endcall %}
</div>
</div>
{% call django_form() %}
{{ crispy(form) }}
{% endcall %}
{% endblock %}
7 changes: 7 additions & 0 deletions common/jinja2/layouts/detail.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{% if title_caption %}
{% block page_subtitle%}
<span class="govuk-caption-xl">
{{ title_caption }}
</span>
{% endblock %}
{% endif %}
<h1 class="govuk-heading-xl">{{ page_title }}</h1>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function QuotaOriginFormset({
groupsWithMembers,
errors,
}) {
const [origins, setOrigins] = useState([...data]);
const emptyOrigin = {
id: "",
pk: "",
Expand All @@ -26,6 +25,10 @@ function QuotaOriginFormset({
end_date_1: "",
end_date_2: "",
};
if (data.length == 0) {
data.push(emptyOrigin);
}
const [origins, setOrigins] = useState([...data]);

const addEmptyOrigin = (e) => {
e.preventDefault();
Expand Down
Loading

0 comments on commit 0595097

Please sign in to comment.