mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
Let GPs nominate service name
Most GP practice services are named after the practice, which is the organisation. So rather than make people re-type the name of their organisation (and potentially make a typo) let’s just let them say ‘yes, that’s the name of my organisation’.
This commit is contained in:
@@ -358,6 +358,31 @@ class StripWhitespaceStringField(StringField):
|
||||
super(StringField, self).__init__(label, **kwargs)
|
||||
|
||||
|
||||
class OnOffField(RadioField):
|
||||
|
||||
def __init__(self, label, choices=None, *args, **kwargs):
|
||||
super().__init__(label, choices=choices or [
|
||||
(True, 'On'),
|
||||
(False, 'Off'),
|
||||
], *args, **kwargs)
|
||||
|
||||
def process_formdata(self, valuelist):
|
||||
if valuelist:
|
||||
value = valuelist[0]
|
||||
self.data = (value == 'True') if value in ['True', 'False'] else value
|
||||
|
||||
def iter_choices(self):
|
||||
for value, label in self.choices:
|
||||
# This overrides WTForms default behaviour which is to check
|
||||
# self.coerce(value) == self.data
|
||||
# where self.coerce returns a string for a boolean input
|
||||
yield (
|
||||
value,
|
||||
label,
|
||||
(self.data in {value, self.coerce(value)})
|
||||
)
|
||||
|
||||
|
||||
class LoginForm(StripWhitespaceForm):
|
||||
email_address = EmailField('Email address', validators=[
|
||||
Length(min=5, max=255),
|
||||
@@ -534,6 +559,38 @@ class RenameOrganisationForm(StripWhitespaceForm):
|
||||
])
|
||||
|
||||
|
||||
class AddGPOrganisationForm(StripWhitespaceForm):
|
||||
|
||||
def __init__(self, *args, service_name='unknown', **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.same_as_service_name.label.text = 'Is your GP practice called ‘{}’?'.format(service_name)
|
||||
self.service_name = service_name
|
||||
|
||||
def get_organisation_name(self):
|
||||
if self.same_as_service_name.data:
|
||||
return self.service_name
|
||||
return self.name.data
|
||||
|
||||
same_as_service_name = OnOffField(
|
||||
'Is your GP practice called the same name as your service?',
|
||||
choices=(
|
||||
(True, 'Yes'),
|
||||
(False, 'No'),
|
||||
),
|
||||
)
|
||||
|
||||
name = StringField(
|
||||
'What’s your practice called?',
|
||||
)
|
||||
|
||||
def validate_name(self, field):
|
||||
if self.same_as_service_name.data is False:
|
||||
if not field.data:
|
||||
raise ValidationError('Can’t be empty')
|
||||
else:
|
||||
field.data = ''
|
||||
|
||||
|
||||
class OrganisationOrganisationTypeForm(StripWhitespaceForm):
|
||||
organisation_type = OrganisationTypeField('What type of organisation is this?')
|
||||
|
||||
@@ -941,19 +998,6 @@ class ServiceLetterContactBlockForm(StripWhitespaceForm):
|
||||
)
|
||||
|
||||
|
||||
class OnOffField(RadioField):
|
||||
def __init__(self, label, *args, **kwargs):
|
||||
super().__init__(label, choices=[
|
||||
(True, 'On'),
|
||||
(False, 'Off'),
|
||||
], *args, **kwargs)
|
||||
|
||||
def process_formdata(self, valuelist):
|
||||
if valuelist:
|
||||
value = valuelist[0]
|
||||
self.data = (value == 'True') if value in ['True', 'False'] else value
|
||||
|
||||
|
||||
class ServiceOnOffSettingForm(StripWhitespaceForm):
|
||||
|
||||
def __init__(self, name, *args, truthy='On', falsey='Off', **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user