Convert radios in edit org type page (basic)

Changes the OrganisationTypeField class used by
OrganisationOrganisationTypeForm.organisation_type

OrganisationTypeField is also used by the forms in
/add-service:
- CreateServiceForm
- CreateNhsServiceForm

Because of that, this commit also includes changes
to the template for that route.

Note: this also moves where OrganisationTypeField
appears in app/main/forms.py so it can use
GovukRadiosField.
This commit is contained in:
Tom Byers
2020-06-26 20:39:20 +01:00
parent 5826dd9733
commit 0cdbb850aa
4 changed files with 28 additions and 30 deletions

View File

@@ -426,26 +426,6 @@ class ForgivingIntegerField(GovukTextInputField):
return super().__call__(value=value, **kwargs)
class OrganisationTypeField(RadioField):
def __init__(
self,
*args,
include_only=None,
validators=None,
**kwargs
):
super().__init__(
*args,
choices=[
(value, label) for value, label in Organisation.TYPES
if not include_only or value in include_only
],
thing='the type of organisation',
validators=validators or [],
**kwargs
)
class FieldWithNoneOption():
# This is a special value that is specific to our forms. This is
@@ -951,6 +931,26 @@ class OnOffField(GovukRadiosField):
)
class OrganisationTypeField(GovukRadiosField):
def __init__(
self,
*args,
include_only=None,
validators=None,
**kwargs
):
super().__init__(
*args,
choices=[
(value, label) for value, label in Organisation.TYPES
if not include_only or value in include_only
],
thing='the type of organisation',
validators=validators or [],
**kwargs
)
# guard against data entries that aren't a role in permissions
def filter_by_permissions(valuelist):
if valuelist is None:

View File

@@ -1,5 +1,4 @@
{% extends "withoutnav_template.html" %}
{% from "components/radios.html" import radios %}
{% from "components/page-header.html" import page_header %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/form.html" import form_wrapper %}
@@ -20,7 +19,7 @@
{{ form.name(param_extensions={"hint": {"text": "You can change this later"}}) }}
{% if not default_organisation_type %}
{{ radios(form.organisation_type) }}
{{ form.organisation_type }}
{% endif %}
{{ page_footer('Add service') }}

View File

@@ -1,4 +1,3 @@
{% from "components/radios.html" import radios %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/page-header.html" import page_header %}
{% from "components/form.html" import form_wrapper %}
@@ -15,7 +14,7 @@
back_link=url_for('.organisation_settings', org_id=current_org.id)
) }}
{% call form_wrapper() %}
{{ radios(form.organisation_type) }}
{{ form.organisation_type }}
{{ page_footer('Save') }}
{% endcall %}
{% endblock %}