diff --git a/app/main/forms.py b/app/main/forms.py index 7548c680c..474f90209 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -98,13 +98,26 @@ class RegisterUserFromInviteForm(Form): email_address = HiddenField('email_address') +# WTF forms does not give a handy way to customise error messages for +# radio button fields so just overriding the default here for use +# in permissions form. +class CustomRadioField(RadioField): + + def pre_validate(self, form): + for v, _ in self.choices: + if self.data == v: + break + else: + raise ValueError(self.gettext('Choose yes or no')) + + class PermisisonsForm(Form): # TODO fix this Radio field so we are not having to test for yes or no rather # use operator equality. - send_messages = RadioField("Send messages", choices=[('yes', 'yes'), ('no', 'no')]) - manage_service = RadioField("Manage service", choices=[('yes', 'yes'), ('no', 'no')]) - manage_api_keys = RadioField("Manage API keys", choices=[('yes', 'yes'), ('no', 'no')]) + send_messages = CustomRadioField("Send messages", choices=[('yes', 'yes'), ('no', 'no')]) + manage_service = CustomRadioField("Manage service", choices=[('yes', 'yes'), ('no', 'no')]) + manage_api_keys = CustomRadioField("Manage API keys", choices=[('yes', 'yes'), ('no', 'no')]) class InviteUserForm(PermisisonsForm): diff --git a/app/main/views/styleguide.py b/app/main/views/styleguide.py index eed30b20e..7d6186aa1 100644 --- a/app/main/views/styleguide.py +++ b/app/main/views/styleguide.py @@ -1,6 +1,7 @@ from flask import render_template, current_app, abort from flask_wtf import Form from wtforms import StringField, PasswordField, TextAreaField, FileField, validators +from app.main.forms import CustomRadioField from utils.template import Template from app.main import main @@ -17,11 +18,14 @@ def styleguide(): code = StringField('Enter code') message = TextAreaField(u'Message') file_upload = FileField('Upload a CSV file to add your recipients’ details') + manage_service = CustomRadioField('Manage service', choices=[('yes', 'yes'), ('no', 'no')]) + manage_templates = CustomRadioField('Manage templates', choices=[('yes', 'yes'), ('no', 'no')]) sms = "Your vehicle tax for ((registration number)) is due on ((date)). Renew online at www.gov.uk/vehicle-tax" form = FormExamples() form.message.data = sms + form.manage_service.data = 'yes' form.validate() template = Template({'content': sms}) diff --git a/app/templates/components/yes-no.html b/app/templates/components/yes-no.html index 0470ab3d6..0d58d14a0 100644 --- a/app/templates/components/yes-no.html +++ b/app/templates/components/yes-no.html @@ -1,15 +1,20 @@ -{% macro yes_no(name, label, current_value=None) %} -
{{ page_footer('Send invitation email') }} diff --git a/app/templates/views/styleguide.html b/app/templates/views/styleguide.html index a45f1a30e..d5addc1f9 100644 --- a/app/templates/views/styleguide.html +++ b/app/templates/views/styleguide.html @@ -247,8 +247,8 @@