diff --git a/app/main/forms.py b/app/main/forms.py index 8e4000771..b0cc3047c 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -2187,21 +2187,9 @@ class AdminSetOrganisationForm(StripWhitespaceForm): class ChooseBrandingForm(StripWhitespaceForm): - FALLBACK_OPTION_VALUE = 'something_else' FALLBACK_OPTION = (FALLBACK_OPTION_VALUE, 'Something else') - options = RadioField('Choose your new branding') - something_else = TextAreaField('Describe the branding you want') - - def __init__(self, service, branding_type): - super().__init__() - self.branding_type = branding_type - self.options.choices = tuple(self.get_available_choices(service, branding_type)) - self.options.label.text = 'Choose your new {} branding'.format(branding_type) - if self.something_else_is_only_option: - self.options.data = self.FALLBACK_OPTION_VALUE - @classmethod def get_available_choices(cls, service, branding_type): return ( @@ -2213,26 +2201,34 @@ class ChooseBrandingForm(StripWhitespaceForm): def something_else_is_only_option(self): return self.options.choices == (self.FALLBACK_OPTION,) - def validate_something_else(self, field): - if self.branding_type == 'letter': - if ( - self.something_else_is_only_option - or self.options.data == self.FALLBACK_OPTION_VALUE - ) and not field.data: - raise ValidationError('Cannot be empty') - - if self.options.data != self.FALLBACK_OPTION_VALUE: - field.data = '' - class ChooseEmailBrandingForm(ChooseBrandingForm): - def __init__(self, service_id): - super().__init__(service_id, branding_type='email') + options = RadioField('Choose your new email branding') + + def __init__(self, service): + super().__init__() + self.options.choices = tuple(self.get_available_choices(service, 'email')) class ChooseLetterBrandingForm(ChooseBrandingForm): - def __init__(self, service_id): - super().__init__(service_id, branding_type='letter') + options = RadioField('Choose your new letter branding') + something_else = TextAreaField('Describe the branding you want') + + def __init__(self, service): + super().__init__() + self.options.choices = tuple(self.get_available_choices(service, 'letter')) + if self.something_else_is_only_option: + self.options.data = self.FALLBACK_OPTION_VALUE + + def validate_something_else(self, field): + if ( + self.something_else_is_only_option + or self.options.data == self.FALLBACK_OPTION_VALUE + ) and not field.data: + raise ValidationError('Cannot be empty') + + if self.options.data != self.FALLBACK_OPTION_VALUE: + field.data = '' class SomethingElseBrandingForm(StripWhitespaceForm):