Skip to content

Commit

Permalink
Update parties forms to use Fieldset
Browse files Browse the repository at this point in the history
  • Loading branch information
hnryjmes committed Jan 13, 2025
1 parent 28f51db commit 8e9a3cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
33 changes: 17 additions & 16 deletions exporter/applications/forms/parties.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from core.helpers import remove_non_printable_characters
from crispy_forms_gds.choices import Choice
from crispy_forms_gds.helper import FormHelper
from crispy_forms_gds.layout import Layout, Submit, HTML
from crispy_forms_gds.layout import Fieldset, Layout, Size, Submit, HTML
from django import forms
from django.core.exceptions import ValidationError
from django.core.validators import MaxLengthValidator, URLValidator
from django.urls import reverse_lazy

from core.common.forms import BaseForm
from core.common.forms import BaseForm, FieldsetForm
from core.forms.layouts import ConditionalRadios, ConditionalRadiosQuestion
from core.forms.widgets import Autocomplete
from exporter.core.constants import CaseTypes, FileUploadFileTypes
Expand Down Expand Up @@ -133,10 +133,9 @@ def new_party_form_group(request, application, strings, back_url, clearance_opti
return FormGroup(forms)


class PartyReuseForm(BaseForm):
class PartyReuseForm(FieldsetForm):
class Layout:
TITLE = "Do you want to reuse an existing party?"
TITLE_AS_LABEL_FOR = "reuse_party"

reuse_party = forms.ChoiceField(
choices=(
Expand All @@ -154,7 +153,7 @@ def get_layout_fields(self):
return ("reuse_party",)


class PartySubTypeSelectForm(BaseForm):
class PartySubTypeSelectForm(FieldsetForm):
"""
This form needs to be instantiated with a Layout.TITLE for the type of party whose data is being set
as per the BaseForm.
Expand Down Expand Up @@ -200,13 +199,11 @@ def clean(self):
class EndUserSubTypeSelectForm(PartySubTypeSelectForm):
class Layout:
TITLE = "Select the type of end user"
TITLE_AS_LABEL_FOR = "sub_type"


class ConsigneeSubTypeSelectForm(PartySubTypeSelectForm):
class Layout:
TITLE = "Select the type of consignee"
TITLE_AS_LABEL_FOR = "sub_type"


class PartyNameForm(BaseForm):
Expand Down Expand Up @@ -395,15 +392,19 @@ def __init__(self, *args, **kwargs):

self.helper = FormHelper()
self.helper.layout = Layout(
HTML.h1(self.title),
HTML.p(self.text_p1),
HTML.p(self.text_p2),
HTML.p(self.text_p3),
HTML.p(self.text_p4),
ConditionalRadios(
"end_user_document_available",
"Yes",
ConditionalRadiosQuestion("No", "end_user_document_missing_reason"),
Fieldset(
HTML.p(self.text_p1),
HTML.p(self.text_p2),
HTML.p(self.text_p3),
HTML.p(self.text_p4),
ConditionalRadios(
"end_user_document_available",
"Yes",
ConditionalRadiosQuestion("No", "end_user_document_missing_reason"),
),
legend=self.title,
legend_size=Size.EXTRA_LARGE,
legend_tag="h1",
),
Submit("submit", "Continue"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def set_end_user(url, authorized_client):
assert not response.context["form"].errors

content = BeautifulSoup(response.content, "html.parser")
heading_element = content.find("h1", class_="govuk-heading-xl")
heading_element = content.find("h1", class_="govuk-fieldset__heading")

assert heading_element.string == "Select the type of end user"
assert heading_element.string.strip() == "Select the type of end user"

response = authorized_client.post(
url,
Expand Down Expand Up @@ -457,6 +457,6 @@ def test_add_end_user_view(authorized_client, data_standard_case):
url = reverse("applications:add_end_user", kwargs={"pk": application_id})
response = authorized_client.get(url)
soup = BeautifulSoup(response.content, "html.parser")
heading_element = soup.find("h1", class_="govuk-heading-xl")
heading_element = soup.find("h1", class_="govuk-fieldset__heading")

assert heading_element.string == "Do you want to reuse an existing party?"
assert heading_element.string.strip() == "Do you want to reuse an existing party?"

0 comments on commit 8e9a3cf

Please sign in to comment.