mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Added error message on template for failing to choose permissions.
For error message over ride from WTF forms radio field created custom field.
This commit is contained in:
@@ -98,13 +98,26 @@ class RegisterUserFromInviteForm(Form):
|
|||||||
email_address = HiddenField('email_address')
|
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):
|
class PermisisonsForm(Form):
|
||||||
|
|
||||||
# TODO fix this Radio field so we are not having to test for yes or no rather
|
# TODO fix this Radio field so we are not having to test for yes or no rather
|
||||||
# use operator equality.
|
# use operator equality.
|
||||||
send_messages = RadioField("Send messages", choices=[('yes', 'yes'), ('no', 'no')])
|
send_messages = CustomRadioField("Send messages", choices=[('yes', 'yes'), ('no', 'no')])
|
||||||
manage_service = RadioField("Manage service", choices=[('yes', 'yes'), ('no', 'no')])
|
manage_service = CustomRadioField("Manage service", choices=[('yes', 'yes'), ('no', 'no')])
|
||||||
manage_api_keys = RadioField("Manage API keys", choices=[('yes', 'yes'), ('no', 'no')])
|
manage_api_keys = CustomRadioField("Manage API keys", choices=[('yes', 'yes'), ('no', 'no')])
|
||||||
|
|
||||||
|
|
||||||
class InviteUserForm(PermisisonsForm):
|
class InviteUserForm(PermisisonsForm):
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from flask import render_template, current_app, abort
|
from flask import render_template, current_app, abort
|
||||||
from flask_wtf import Form
|
from flask_wtf import Form
|
||||||
from wtforms import StringField, PasswordField, TextAreaField, FileField, validators
|
from wtforms import StringField, PasswordField, TextAreaField, FileField, validators
|
||||||
|
from app.main.forms import CustomRadioField
|
||||||
from utils.template import Template
|
from utils.template import Template
|
||||||
from app.main import main
|
from app.main import main
|
||||||
|
|
||||||
@@ -17,11 +18,14 @@ def styleguide():
|
|||||||
code = StringField('Enter code')
|
code = StringField('Enter code')
|
||||||
message = TextAreaField(u'Message')
|
message = TextAreaField(u'Message')
|
||||||
file_upload = FileField('Upload a CSV file to add your recipients’ details')
|
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"
|
sms = "Your vehicle tax for ((registration number)) is due on ((date)). Renew online at www.gov.uk/vehicle-tax"
|
||||||
|
|
||||||
form = FormExamples()
|
form = FormExamples()
|
||||||
form.message.data = sms
|
form.message.data = sms
|
||||||
|
form.manage_service.data = 'yes'
|
||||||
form.validate()
|
form.validate()
|
||||||
|
|
||||||
template = Template({'content': sms})
|
template = Template({'content': sms})
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
{% macro yes_no(name, label, current_value=None) %}
|
{% macro yes_no(field, current_value=None) %}
|
||||||
<fieldset class='yes-no'>
|
<fieldset class='yes-no {% if field.errors %} error{% endif %}'>
|
||||||
<legend class='yes-no-label'>
|
<legend class='yes-no-label'>
|
||||||
{{ label }}
|
{{ field.label }}
|
||||||
|
{% if field.errors %}
|
||||||
|
<span class="error-message">
|
||||||
|
{{ field.errors[0] }}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
</legend>
|
</legend>
|
||||||
<div class='yes-no-fields inline'>
|
<div class='yes-no-fields inline'>
|
||||||
<label class='block-label'>
|
<label class='block-label'>
|
||||||
<input type='radio' name='{{ name }}' value='yes' {% if current_value == 'yes' %}checked{% endif %} />
|
<input type='radio' name='{{ field.name }}' value='yes' {% if current_value == 'yes' %}checked{% endif %} />
|
||||||
Yes
|
Yes
|
||||||
</label>
|
</label>
|
||||||
<label class='block-label'>
|
<label class='block-label'>
|
||||||
<input type='radio' name='{{ name }}' value='no' {% if current_value == 'no' %}checked{% endif %} />
|
<input type='radio' name='{{ field.name }}' value='no' {% if current_value == 'no' %}checked{% endif %} />
|
||||||
No
|
No
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ Manage users – GOV.UK Notify
|
|||||||
Permissions
|
Permissions
|
||||||
</legend>
|
</legend>
|
||||||
<span class="form-hint">All team members can see message history</span>
|
<span class="form-hint">All team members can see message history</span>
|
||||||
{{ yes_no(form.send_messages.name, form.send_messages.label, form.send_messages.data) }}
|
{{ yes_no(form.send_messages, form.send_messages.data) }}
|
||||||
{{ yes_no(form.manage_service.name, form.manage_service.label, form.manage_service.data) }}
|
{{ yes_no(form.manage_service, form.manage_service.data) }}
|
||||||
{{ yes_no(form.manage_api_keys.name, form.manage_api_keys.label, form.manage_api_keys.data) }}
|
{{ yes_no(form.manage_api_keys, form.manage_api_keys.data) }}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
{{ page_footer(
|
{{ page_footer(
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ Manage users – GOV.UK Notify
|
|||||||
Permissions
|
Permissions
|
||||||
</legend>
|
</legend>
|
||||||
<span class="form-hint">All team members can see message history</span>
|
<span class="form-hint">All team members can see message history</span>
|
||||||
{{ yes_no(form.send_messages.name, form.send_messages.label, form.send_messages.data) }}
|
{{ yes_no(form.send_messages, form.send_messages.data) }}
|
||||||
{{ yes_no(form.manage_service.name, form.manage_service.label, form.manage_service.data) }}
|
{{ yes_no(form.manage_service, form.manage_service.data) }}
|
||||||
{{ yes_no(form.manage_api_keys.name, form.manage_api_keys.label, form.manage_api_keys.data) }}
|
{{ yes_no(form.manage_api_keys, form.manage_api_keys.data) }}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
{{ page_footer('Send invitation email') }}
|
{{ page_footer('Send invitation email') }}
|
||||||
|
|||||||
@@ -247,8 +247,8 @@
|
|||||||
<div class="grid-row">
|
<div class="grid-row">
|
||||||
<div class='column-half'>
|
<div class='column-half'>
|
||||||
<fieldset class='yes-no-wrapper'>
|
<fieldset class='yes-no-wrapper'>
|
||||||
{{ yes_no('manage_service', 'Manage service', True) }}
|
{{ yes_no(form.manage_service, form.manage_service.data) }}
|
||||||
{{ yes_no('templates', 'Create templates', True) }}
|
{{ yes_no(form.manage_templates, form.manage_templates.data) }}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user