Use Flask for routing

This commit:
- replaces links that look like buttons with forms and submit buttons
- splits the view code for SMS into its own file
- moves the routing into the Python by adding handling for `post` requests
- uses Flask’s `url_for` to generate URLs, rather than hard coding them (so that
  it’s easier to change the URLs)
- chages the URLs for sending text messages
This commit is contained in:
Chris Hill-Scott
2015-12-10 21:15:20 +00:00
parent dbc55e76b0
commit 8a34fa7e0a
6 changed files with 105 additions and 90 deletions

View File

@@ -41,47 +41,6 @@ def addservice():
return render_template('views/add-service.html')
@main.route("/send-sms")
def sendsms():
return render_template(
'views/send-sms.html',
message_templates=[
{
'name': 'Reminder',
'body': """
Vehicle tax: Your vehicle tax for ((registration number)) expires on ((date)).
Tax your vehicle at www.gov.uk/vehicle-tax
"""
},
{
'name': 'Warning',
'body': """
Vehicle tax: Your vehicle tax for ((registration number)) has expired.
Tax your vehicle at www.gov.uk/vehicle-tax
"""
},
]
)
@main.route("/check-sms")
def checksms():
return render_template(
'views/check-sms.html',
recipients=[
{'phone': "+44 7815838437", 'registration': 'LC12 BFL', 'date': '25 December 2015'},
{'phone': "+44 7815838437", 'registration': 'LC12 BFL', 'date': '25 December 2015'},
{'phone': "+44 7815838437", 'registration': 'LC12 BFL', 'date': '25 December 2015'},
{'phone': "+44 7815838437", 'registration': 'LC12 BFL', 'date': '25 December 2015'},
{'phone': "+44 7815838437", 'registration': 'LC12 BFL', 'date': '25 December 2015'}
],
message_template="""
Vehicle tax: Your vehicle tax for ((registration number)) expires on ((date)).
Tax your vehicle at www.gov.uk/vehicle-tax
"""
)
@main.route("/email-not-received")
def emailnotreceived():
return render_template('views/email-not-received.html')

51
app/main/views/sms.py Normal file
View File

@@ -0,0 +1,51 @@
from flask import request, render_template, redirect, url_for
from flask_login import login_required
from app.main import main
@main.route("/sms/send", methods=['GET', 'POST'])
def sendsms():
if request.method == 'GET':
return render_template(
'views/send-sms.html',
message_templates=[
{
'name': 'Reminder',
'body': """
Vehicle tax: Your vehicle tax for ((registration number)) expires on ((date)).
Tax your vehicle at www.gov.uk/vehicle-tax
"""
},
{
'name': 'Warning',
'body': """
Vehicle tax: Your vehicle tax for ((registration number)) has expired.
Tax your vehicle at www.gov.uk/vehicle-tax
"""
},
]
)
elif request.method == 'POST':
return redirect(url_for('.checksms'))
@main.route("/sms/check", methods=['GET', 'POST'])
def checksms():
if request.method == 'GET':
return render_template(
'views/check-sms.html',
recipients=[
{'phone': "+44 7815838437", 'registration': 'LC12 BFL', 'date': '24 December 2015'},
{'phone': "+44 7815838437", 'registration': 'DU04 AOM', 'date': '25 December 2015'},
{'phone': "+44 7815838437", 'registration': 'M91 MJB', 'date': '26 December 2015'},
{'phone': "+44 7815838437", 'registration': 'Y249 NPU', 'date': '31 December 2015'},
{'phone': "+44 7815838437", 'registration': 'LG55 UGB', 'date': '1 January 2016'}
],
message_template="""
Vehicle tax: Your vehicle tax for ((registration number)) expires on ((date)).
Tax your vehicle at www.gov.uk/vehicle-tax
"""
)
elif request.method == 'POST':
return redirect(url_for('.showjob'))