mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
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:
@@ -3,4 +3,4 @@ from flask import Blueprint
|
|||||||
main = Blueprint('main', __name__)
|
main = Blueprint('main', __name__)
|
||||||
|
|
||||||
|
|
||||||
from app.main.views import index, sign_in, register, two_factor, verify
|
from app.main.views import index, sign_in, register, two_factor, verify, sms
|
||||||
|
|||||||
@@ -41,47 +41,6 @@ def addservice():
|
|||||||
return render_template('views/add-service.html')
|
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")
|
@main.route("/email-not-received")
|
||||||
def emailnotreceived():
|
def emailnotreceived():
|
||||||
return render_template('views/email-not-received.html')
|
return render_template('views/email-not-received.html')
|
||||||
|
|||||||
51
app/main/views/sms.py
Normal file
51
app/main/views/sms.py
Normal 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'))
|
||||||
@@ -17,7 +17,10 @@
|
|||||||
{{ sms_message(message_template) }}
|
{{ sms_message(message_template) }}
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a class="button" href="/jobs/job" role="button">Send {{recipients|length}} text messages</a>
|
<form method="POST" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||||
|
<input type="submit" class="button" value="Send {{recipients|length}} text messages" />
|
||||||
|
</form>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ GOV.UK Notify | Dashboard
|
|||||||
<h1 class="heading-xlarge">Dashboard</h1>
|
<h1 class="heading-xlarge">Dashboard</h1>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="send-sms">Send text messages</a></li>
|
<li><a href="{{ url_for('.sendsms') }}">Send text messages</a></li>
|
||||||
<li><a href="send-email">Send email messages</a></li>
|
<li><a href="{{ url_for('.sendemail') }}">Send email messages</a></li>
|
||||||
<li><a href="jobs">View notifications activity</a></li>
|
<li><a href="{{ url_for('.showjobs') }}">View notifications activity</a></li>
|
||||||
<li><a href="user-profile">User profile</a></li>
|
<li><a href="{{ url_for('.userprofile') }}">User profile</a></li>
|
||||||
<li><a href="manage-users">Manage users</a></li>
|
<li><a href="{{ url_for('.manageusers') }}">Manage users</a></li>
|
||||||
<li><a href="manage-templates">Manage templates</a></li>
|
<li><a href="{{ url_for('.managetemplates')}}">Manage templates</a></li>
|
||||||
<li><a href="service-settings">Service settings</a></li>
|
<li><a href="{{ url_for('.servicesettings') }}">Service settings</a></li>
|
||||||
<li><a href="api-keys">API keys and documentation</a></li>
|
<li><a href="{{ url_for('.apikeys') }}">API keys and documentation</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,48 +6,50 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<form method="POST" enctype="multipart/form-data">
|
||||||
|
<div class="grid-row">
|
||||||
|
<div class="column-two-thirds">
|
||||||
|
|
||||||
<div class="grid-row">
|
<h1 class="heading-xlarge">Send text messages</h1>
|
||||||
<div class="column-two-thirds">
|
|
||||||
|
|
||||||
<h1 class="heading-xlarge">Send text messages</h1>
|
<h2 class="heading-medium">1. Choose text message template</h2>
|
||||||
|
{% for template in message_templates %}
|
||||||
|
<div class="template-picker-option">
|
||||||
|
<label>
|
||||||
|
<span class="template-picker-name">{{ template.name }}</span>
|
||||||
|
<input type="radio" name="template" value="{{ template.name }}" />
|
||||||
|
{{ sms_message(template.body) }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
<h2 class="heading-medium">1. Choose text message template</h2>
|
<p>
|
||||||
{% for template in message_templates %}
|
<a href="{{ url_for(".managetemplates") }}">Create a new template</a>
|
||||||
<div class="template-picker-option">
|
</p>
|
||||||
<label>
|
|
||||||
<span class="template-picker-name">{{ template.name }}</span>
|
<h2 class="heading-medium">2. Add recipients</h2>
|
||||||
<input type="radio" name="template" value="{{ template.name }}" />
|
|
||||||
{{ sms_message(template.body) }}
|
<p>
|
||||||
</label>
|
Add recipients by uploading a CSV
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Format the cells as ‘text’ in your spreadsheet app – this stores the mobile
|
||||||
|
numbers correctly
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
You can also <a href="#">download an example</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input type="file" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||||
|
<input type="submit" class="button" value="Continue" />
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
</div>
|
||||||
|
</form>
|
||||||
<p>
|
|
||||||
<a href="#">Create a new template</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h2 class="heading-medium">2. Add recipients</h2>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Add recipients by uploading a CSV
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Format the cells as ‘text’ in your spreadsheet app – this stores the mobile
|
|
||||||
numbers correctly
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
You can also <a href="#">download an example</a>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<input type="file" />
|
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<a class="button" href="/check-sms" role="button">Continue</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user