Add a WTForms-compatible textbox macro

This macro:
- accepts a WTForm form field as a parameter
- renders a form field which follows the GOV.UK Elements patterns, both visually
  and in markup terms

It then changes any page which uses either:
- the old, non-WTForms macro or
- the old, WTFforms `render_field` macro

…to use this new macro and removes both of the old ones.

It also adds the option to display hint text above the textbox.
This commit is contained in:
Chris Hill-Scott
2016-01-11 13:15:10 +00:00
parent dd242752c7
commit e8fe8c50ba
21 changed files with 140 additions and 105 deletions

View File

@@ -2,6 +2,7 @@ from flask import render_template, redirect, request, url_for, abort
from flask_login import login_required
from app.main import main
from app.main.forms import ConfirmPasswordForm, ServiceNameForm
service = {
'name': 'Service name',
@@ -20,10 +21,15 @@ def service_settings():
@main.route("/service-settings/name", methods=['GET', 'POST'])
def name():
form = ServiceNameForm()
form.service_name.data = 'Service name'
if request.method == 'GET':
return render_template(
'views/service-settings/name.html',
service=service
service=service,
form=form
)
elif request.method == 'POST':
return redirect(url_for('.confirm_name_change'))
@@ -31,10 +37,14 @@ def name():
@main.route("/service-settings/name/confirm", methods=['GET', 'POST'])
def confirm_name_change():
form = ConfirmPasswordForm()
if request.method == 'GET':
return render_template(
'views/service-settings/confirm.html',
heading='Change your service name'
heading='Change your service name',
form=form
)
elif request.method == 'POST':
return redirect(url_for('.service_settings'))
@@ -64,11 +74,15 @@ def status():
@main.route("/service-settings/status/confirm", methods=['GET', 'POST'])
def confirm_status_change():
form = ConfirmPasswordForm()
if request.method == 'GET':
return render_template(
'views/service-settings/confirm.html',
heading='Turn off all outgoing notifications',
destructive=True
destructive=True,
form=form
)
elif request.method == 'POST':
return redirect(url_for('.service_settings'))
@@ -87,11 +101,15 @@ def delete():
@main.route("/service-settings/delete/confirm", methods=['GET', 'POST'])
def confirm_delete():
form = ConfirmPasswordForm()
if request.method == 'GET':
return render_template(
'views/service-settings/confirm.html',
heading='Delete this service from Notify',
destructive=True
destructive=True,
form=form
)
elif request.method == 'POST':
return redirect(url_for('.dashboard'))

View File

@@ -1,7 +1,24 @@
from flask import render_template
from flask_wtf import Form
from wtforms import StringField, PasswordField, TextAreaField, validators
from app.main import main
@main.route('/_styleguide')
def styleguide():
return render_template('views/styleguide.html')
class FormExamples(Form):
username = StringField(u'Username')
password = PasswordField(u'Password', [validators.required()])
message = TextAreaField(u'Message')
form = FormExamples()
form.message.data = "Your vehicle tax for ((registration number)) is due on ((date)). Renew online at www.gov.uk/vehicle-tax" # noqa
form.validate()
return render_template(
'views/styleguide.html',
form=form
)

View File

@@ -1,6 +1,7 @@
from flask import request, render_template, redirect, url_for
from app.main import main
from app.main.forms import TemplateForm
@main.route("/templates")
@@ -10,12 +11,17 @@ def manage_templates():
@main.route("/templates/template", methods=['GET', 'POST'])
def add_template():
form = TemplateForm()
form.template_name.data = 'Reminder'
form.template_body.data = 'Vehicle tax: Your vehicle tax for ((registration number)) expires on ((date)). Tax your vehicle at www.gov.uk/vehicle-tax' # noqa
if request.method == 'GET':
return render_template(
'views/edit-template.html',
template_name='Reminder',
template_body='Vehicle tax: Your vehicle tax for ((registration number)) expires on ((date)). Tax your vehicle at www.gov.uk/vehicle-tax', # noqa
h1='Edit template'
h1='Edit template',
form=form
)
elif request.method == 'POST':
return redirect(url_for('.manage_templates'))
@@ -23,10 +29,14 @@ def add_template():
@main.route("/templates/template/add", methods=['GET', 'POST'])
def edit_template():
form = TemplateForm()
if request.method == 'GET':
return render_template(
'views/edit-template.html',
h1='Add template'
h1='Add template',
form=form
)
elif request.method == 'POST':
return redirect(url_for('.manage_templates'))