From 7492fa909d0c69109b2eb5dac7d0c165f30335e3 Mon Sep 17 00:00:00 2001 From: Jim Narey Date: Fri, 8 Mar 2024 10:12:59 +0000 Subject: [PATCH] Use RegistrantTypeChoices to populate form So we only have registrant types recorded in one place. --- request_a_govuk_domain/request/forms.py | 26 +++++++------------------ 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/request_a_govuk_domain/request/forms.py b/request_a_govuk_domain/request/forms.py index fbc582c4..40057289 100644 --- a/request_a_govuk_domain/request/forms.py +++ b/request_a_govuk_domain/request/forms.py @@ -16,6 +16,7 @@ ) from .utils import organisations_list +from .models.organisation import RegistrantTypeChoices class NameForm(forms.Form): @@ -197,27 +198,14 @@ def __init__(self, *args, **kwargs): class RegistrantTypeForm(forms.Form): - REGISTRANT_TYPES = ( - Choice("central_gov", "Central government department or agency"), - Choice("alb", "Non-departmental body - also known as an arm's length body"), - Choice("fire_service", "Fire service"), - Choice("county_council", "County, borough, metropolitan or district council"), - Choice("parish_council", "Parish, town or community council"), - Choice("village_council", "Neighbourhood or village council"), - Choice("combined_authority", "Combined or unitary authority"), - Choice("pcc", "Police and crime commissioner"), - Choice("joint_authority", "Joint authority"), - Choice("joint_committee", "Joint committee"), - Choice( - "representing_public_sector", - "Representing public sector bodies", - divider="Or", - ), - Choice("none", "None of the above"), - ) + registrant_types = [ + Choice(*item) for item in RegistrantTypeChoices.__members__.items() + ] + registrant_types[-1].divider = "Or" + registrant_types.append(Choice("none", "None of the above")) registrant_type = forms.ChoiceField( - choices=REGISTRANT_TYPES, + choices=registrant_types, widget=forms.RadioSelect, label="Your registrant must be from an eligible organisation to get a .gov.uk domain name.", error_messages={"required": "Please select from one of the choices"},