mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-06 08:58:44 -04:00
Add routing and pages for managing templates
So that users can see what it the flow is like to: - add new templates - edit existing templates
This commit is contained in:
@@ -4,5 +4,5 @@ main = Blueprint('main', __name__)
|
||||
|
||||
|
||||
from app.main.views import (
|
||||
index, sign_in, register, two_factor, verify, sms, add_service, code_not_received, jobs, dashboard
|
||||
index, sign_in, register, two_factor, verify, sms, add_service, code_not_received, jobs, dashboard, templates
|
||||
)
|
||||
|
||||
@@ -9,12 +9,6 @@ def index():
|
||||
return render_template('views/signedout.html')
|
||||
|
||||
|
||||
@main.route("/dashboard")
|
||||
@login_required
|
||||
def dashboard():
|
||||
return render_template('views/dashboard.html')
|
||||
|
||||
|
||||
@main.route("/govuk")
|
||||
def govuk():
|
||||
return render_template('views/govuk_template.html')
|
||||
@@ -70,11 +64,6 @@ def apikeys():
|
||||
return render_template('views/api-keys.html')
|
||||
|
||||
|
||||
@main.route("/manage-templates")
|
||||
def managetemplates():
|
||||
return render_template('views/manage-templates.html')
|
||||
|
||||
|
||||
@main.route("/edit-template")
|
||||
def edittemplate():
|
||||
return render_template('views/edit-template.html')
|
||||
@main.route("/verification-not-received")
|
||||
def verificationnotreceived():
|
||||
return render_template('views/verification-not-received.html')
|
||||
|
||||
32
app/main/views/templates.py
Normal file
32
app/main/views/templates.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from flask import request, render_template, redirect, url_for
|
||||
|
||||
from app.main import main
|
||||
|
||||
|
||||
@main.route("/templates")
|
||||
def manage_templates():
|
||||
return render_template('views/manage-templates.html')
|
||||
|
||||
|
||||
@main.route("/templates/template", methods=['GET', 'POST'])
|
||||
def add_template():
|
||||
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'
|
||||
)
|
||||
elif request.method == 'POST':
|
||||
return redirect(url_for('.manage_templates'))
|
||||
|
||||
|
||||
@main.route("/templates/template/add", methods=['GET', 'POST'])
|
||||
def edit_template():
|
||||
if request.method == 'GET':
|
||||
return render_template(
|
||||
'views/edit-template.html',
|
||||
h1='Add template'
|
||||
)
|
||||
elif request.method == 'POST':
|
||||
return redirect(url_for('.manage_templates'))
|
||||
@@ -1,11 +1,9 @@
|
||||
{% macro submit_form(button_text, back_link) %}
|
||||
{% macro submit_form(button_text, back_link=False) %}
|
||||
<div class="submit-form">
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||
<input type="submit" class="button" value="{{ button_text }}" />
|
||||
{% if back_link %}
|
||||
<a class="submit-form-back-link" role="button" href="{{ back_link }}">Back</a>
|
||||
{% endif %}
|
||||
</form>
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||
<input type="submit" class="button" value="{{ button_text }}" />
|
||||
{% if back_link %}
|
||||
<a class="submit-form-back-link" role="button" href="{{ back_link }}">Back</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
10
app/templates/components/textbox.html
Normal file
10
app/templates/components/textbox.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{% macro textbox(name, label, value='', small=True) %}
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="{{ name }}">{{ label }}</label>
|
||||
{% if small %}
|
||||
<input class="form-control" id="{{ name }}" name="{{ name }}" type="text" value="{{ value }}">
|
||||
{% else %}
|
||||
<textarea class="form-control" id="{{ name }}" name="{{ name }}" cols="30" rows="10">{{ value }}</textarea>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
@@ -15,50 +15,54 @@
|
||||
|
||||
<h2 class="heading-medium">Check and confirm</h2>
|
||||
|
||||
{{ submit_form(
|
||||
"Send {} text messages".format(number_of_recipients),
|
||||
url_for(".sendsms")
|
||||
) }}
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
|
||||
<h3 class="heading-small">First 3 messages</h2>
|
||||
{{ submit_form(
|
||||
"Send {} text messages".format(number_of_recipients),
|
||||
url_for(".sendsms")
|
||||
) }}
|
||||
|
||||
{% if recipients.first_three and recipients.last_three %}
|
||||
<h3 class="heading-small">First 3 messages</h2>
|
||||
|
||||
{% for recipient in recipients.first_three %}
|
||||
{{ sms_message(
|
||||
message_template|replace_placeholders(recipient),
|
||||
"{}".format(recipient['phone'])
|
||||
) }}
|
||||
{% endfor %}
|
||||
{% if recipients.first_three and recipients.last_three %}
|
||||
|
||||
<h3 class="heading-small">Last 3 messages</h2>
|
||||
{% for recipient in recipients.first_three %}
|
||||
{{ sms_message(
|
||||
message_template|replace_placeholders(recipient),
|
||||
"{}".format(recipient['phone'])
|
||||
) }}
|
||||
{% endfor %}
|
||||
|
||||
{% for recipient in recipients.last_three %}
|
||||
{{ sms_message(
|
||||
message_template|replace_placeholders(recipient),
|
||||
"{}".format(recipient['phone'])
|
||||
) }}
|
||||
{% endfor %}
|
||||
<h3 class="heading-small">Last 3 messages</h2>
|
||||
|
||||
{% else %}
|
||||
{% for recipient in recipients.last_three %}
|
||||
{{ sms_message(
|
||||
message_template|replace_placeholders(recipient),
|
||||
"{}".format(recipient['phone'])
|
||||
) }}
|
||||
{% endfor %}
|
||||
|
||||
{% for recipient in recipients.all %}
|
||||
{{ sms_message(
|
||||
message_template|replace_placeholders(recipient),
|
||||
"{}".format(recipient['phone'])
|
||||
) }}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
{% for recipient in recipients.all %}
|
||||
{{ sms_message(
|
||||
message_template|replace_placeholders(recipient),
|
||||
"{}".format(recipient['phone'])
|
||||
) }}
|
||||
{% endfor %}
|
||||
|
||||
<p>
|
||||
<a href="#">See all</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{{ submit_form(
|
||||
"Send {} text messages".format(number_of_recipients),
|
||||
url_for(".sendsms")
|
||||
) }}
|
||||
<p>
|
||||
<a href="#">See all</a>
|
||||
</p>
|
||||
|
||||
{{ submit_form(
|
||||
"Send {} text messages".format(number_of_recipients),
|
||||
url_for(".sendsms")
|
||||
) }}
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/submit-form.html" import submit_form %}
|
||||
|
||||
{% block page_title %}
|
||||
GOV.UK Notify | Edit template
|
||||
@@ -6,13 +8,14 @@ GOV.UK Notify | Edit template
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<h1 class="heading-xlarge">{{ h1 }}</h1>
|
||||
|
||||
<h1 class="heading-xlarge">Edit template</h1>
|
||||
|
||||
<p>Here's where you can edit an exiting template (including delete) or add a new one</p>
|
||||
<form method="post">
|
||||
{{ textbox(name='template_name', label='Template name', value=template_name) }}
|
||||
{{ textbox(name='template_body', label='Message', small=False, value=template_body) }}
|
||||
{{ submit_form('Save and continue') }}
|
||||
</form>
|
||||
|
||||
<p><a href="manage-templates">Back to manage templates</a></p>
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -7,15 +7,17 @@ GOV.UK Notify | Manage templates
|
||||
{% block maincolumn_content %}
|
||||
|
||||
|
||||
<h1 class="heading-xlarge">Manage templates</h1>
|
||||
<h1 class="heading-xlarge">Manage templates</h1>
|
||||
|
||||
<p>Here's where you can view templates, choose to add one, or edit/delete one.</p>
|
||||
<p>Here's where you can view templates, choose to add one, or edit/delete one.</p>
|
||||
|
||||
<p><a href="edit-template">Here is my first template</a></p>
|
||||
<p>
|
||||
<a href="{{ url_for('.edit_template') }}">Here is my first template</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a class="button" href="edit-template" role="button">Add a new message template</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="button" href="{{ url_for('.edit_template') }}" role="button">Add a new message template</a>
|
||||
</p>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
{% endfor %}
|
||||
|
||||
<p>
|
||||
or <a href="{{ url_for(".managetemplates") }}">create a new template</a>
|
||||
or <a href="{{ url_for(".add_template") }}">create a new template</a>
|
||||
</p>
|
||||
|
||||
<h2 class="heading-medium">2. Add recipients</h2>
|
||||
|
||||
17
tests/app/main/views/test_templates.py
Normal file
17
tests/app/main/views/test_templates.py
Normal file
@@ -0,0 +1,17 @@
|
||||
def test_should_return_list_of_all_templates(notifications_admin):
|
||||
response = notifications_admin.test_client().get('/templates')
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_show_page_for_one_templates(notifications_admin):
|
||||
response = notifications_admin.test_client().get('/templates/template')
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_redirect_when_saving_a_template(notifications_admin):
|
||||
response = notifications_admin.test_client().post('/templates/template')
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == 'http://localhost/templates'
|
||||
Reference in New Issue
Block a user