Merge pull request #200 from alphagov/email-flow-fixes

Consolidate page templates for emails + texts
This commit is contained in:
Adam Shimali
2016-02-26 12:02:14 +00:00
10 changed files with 100 additions and 99 deletions

View File

@@ -13,6 +13,7 @@ from utils.template import Template
from app import job_api_client
from app.main import main
from app.main.dao import templates_dao
from app.main.dao import services_dao
now = time.strftime('%H:%M')
@@ -37,6 +38,7 @@ def view_jobs(service_id):
@main.route("/services/<service_id>/jobs/<job_id>")
@login_required
def view_job(service_id, job_id):
service = services_dao.get_service_by_id_or_404(service_id)
try:
job = job_api_client.get_job(service_id, job_id)['data']
messages = []
@@ -56,9 +58,11 @@ def view_job(service_id, job_id):
uploaded_file_name=job['original_file_name'],
uploaded_file_time=job['created_at'],
template=Template(
templates_dao.get_service_template_or_404(service_id, job['template'])['data']
templates_dao.get_service_template_or_404(service_id, job['template'])['data'],
prefix=service['name']
),
service_id=service_id
service_id=service_id,
service=service
)
except HTTPError as e:
if e.status_code == 404:

View File

@@ -28,11 +28,16 @@ from app.main.dao import services_dao
from app import job_api_client
from app.utils import validate_recipient, InvalidPhoneError, InvalidEmailError
page_headings = {
'email': 'Send emails',
'sms': 'Send text messages'
}
@main.route("/services/<service_id>/send/<template_type>", methods=['GET'])
def choose_template(service_id, template_type):
services_dao.get_service_by_id_or_404(service_id)
service = services_dao.get_service_by_id_or_404(service_id)
if template_type not in ['email', 'sms']:
abort(404)
@@ -44,11 +49,17 @@ def choose_template(service_id, template_type):
else:
raise e
return render_template(
'views/choose-{}-template.html'.format(template_type),
'views/choose-template.html',
templates=[
Template(template) for template in templates_dao.get_service_templates(service_id)['data']
Template(
template,
prefix=service['name']
) for template in templates_dao.get_service_templates(service_id)['data']
if template['template_type'] == template_type
],
template_type=template_type,
page_heading=page_headings[template_type],
service=service,
has_jobs=len(jobs),
service_id=service_id
)
@@ -76,7 +87,8 @@ def send_messages(service_id, template_id):
service = services_dao.get_service_by_id_or_404(service_id)
template = Template(
templates_dao.get_service_template_or_404(service_id, template_id)['data']
templates_dao.get_service_template_or_404(service_id, template_id)['data'],
prefix=service['name']
)
return render_template(
@@ -97,7 +109,12 @@ def get_example_csv(service_id, template_id):
output = io.StringIO()
writer = csv.writer(output)
writer.writerow(['to'] + placeholders)
writer.writerow([current_user.mobile_number] + ["test {}".format(header) for header in placeholders])
writer.writerow([
{
'email': current_user.email_address,
'sms': current_user.mobile_number
}[template['template_type']]
] + ["test {}".format(header) for header in placeholders])
return output.getvalue(), 200, {'Content-Type': 'text/csv; charset=utf-8'}
@@ -130,6 +147,7 @@ def check_messages(service_id, upload_id):
upload_data = session['upload_data']
template_id = upload_data.get('template_id')
service = services_dao.get_service_by_id_or_404(service_id)
if request.method == 'GET':
contents = s3download(service_id, upload_id)
@@ -141,17 +159,18 @@ def check_messages(service_id, upload_id):
template = Template(
raw_template,
values=upload_result['rows'][0] if upload_result['valid'] else {},
drop_values={'to'}
drop_values={'to'},
prefix=service['name']
)
return render_template(
'views/check-sms.html',
'views/check.html',
upload_result=upload_result,
template=template,
column_headers=['to'] + list(
template.placeholders if upload_result['valid'] else template.placeholders_as_markup
),
page_heading=page_headings[template.template_type],
column_headers=['to'] + list(template.placeholders_as_markup),
original_file_name=upload_data.get('original_file_name'),
service_id=service_id,
service=service,
form=CsvUploadForm()
)
elif request.method == 'POST':
@@ -193,7 +212,7 @@ def _get_rows(contents, raw_template):
rows.append(row)
try:
validate_recipient(
row['to'],
row.get('to', ''),
template_type=raw_template['template_type']
)
Template(raw_template, values=row, drop_values={'to'}).replaced

View File

@@ -1,18 +0,0 @@
{% extends "withnav_template.html" %}
{% block page_title %}
Send email GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">Send email</h1>
<p>This page will be where we check the email messages we're about to send</p>
<p>
<a class="button" href="dashboard" role="button">Send email messages</a>
</p>
{% endblock %}

View File

@@ -1,4 +1,5 @@
{% extends "withnav_template.html" %}
{% from "components/email-message.html" import email_message %}
{% from "components/sms-message.html" import sms_message %}
{% from "components/table.html" import list_table, field %}
{% from "components/placeholder.html" import placeholder %}
@@ -6,7 +7,7 @@
{% from "components/page-footer.html" import page_footer %}
{% block page_title %}
Check and confirm GOV.UK Notify
{{ "Check and confirm" if upload_result.valid else page_heading }} GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
@@ -25,18 +26,25 @@
{% endif %}
<h1 class="heading-large">
{{ "Check and confirm" if upload_result.valid else "Send text messages" }}
{{ "Check and confirm" if upload_result.valid else page_heading }}
</h1>
<div class="grid-row">
<div class="column-two-thirds">
{% if template.missing_data or template.additional_data %}
{{ sms_message(template.formatted_as_markup)}}
{% else %}
{{ sms_message(template.replaced)}}
{% endif %}
{% if 'email' == template.template_type %}
{{ email_message(
template.subject,
template.replaced if upload_result.valid else template.formatted_as_markup,
from_address='{}@notifications.service.gov.uk'.format(service.email_from),
from_name=service.name
)}}
{% elif 'sms' == template.template_type %}
<div class="grid-row">
<div class="column-two-thirds">
{{ sms_message(
template.replaced if upload_result.valid else template.formatted_as_markup
)}}
</div>
</div>
</div>
{% endif %}
{% if upload_result.valid %}
<form method="post" enctype="multipart/form-data">
@@ -53,7 +61,7 @@
caption=original_file_name,
field_headings=column_headers
) %}
{% if item.to|valid_phone_number %}
{% if item.to or ''|valid_phone_number %}
{% call field() %}
{{ item.to }}
{% endcall %}

View File

@@ -1,36 +0,0 @@
{% extends "withnav_template.html" %}
{% from "components/email-message.html" import email_message %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/textbox.html" import textbox %}
{% block page_title %}
Send emails GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">Send emails</h1>
<form method="POST" enctype="multipart/form-data">
{% if templates %}
<div class="grid-row">
{% for template in templates %}
<div class="column-two-thirds">
{{ email_message(template.subject, template.formatted_as_markup, name=template.name) }}
</div>
<div class="column-one-third">
<div class="sms-message-use-links">
<a href="{{ url_for(".edit_service_template", service_id=service_id, template_id=template.id) }}">Edit template</a>
</div>
</div>
{% endfor %}
</div>
{% endif %}
<p>
<a href="{{ url_for('.add_service_template', service_id=service_id, template_type='email') }}" class="button">Add a new template</a>
</p>
</form>
{% endblock %}

View File

@@ -1,15 +1,16 @@
{% extends "withnav_template.html" %}
{% from "components/email-message.html" import email_message %}
{% from "components/sms-message.html" import sms_message %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/textbox.html" import textbox %}
{% block page_title %}
Send text messages GOV.UK Notify
{{ page_heading }} GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">Send text messages</h1>
<h1 class="heading-large">{{ page_heading }}</h1>
<form method="POST" enctype="multipart/form-data">
@@ -26,7 +27,15 @@
<div class="grid-row">
{% for template in templates %}
<div class="column-two-thirds">
{{ sms_message(template.formatted_as_markup, name=template.name) }}
{% if 'email' == template_type %}
{{ email_message(
template.subject,
template.formatted_as_markup,
name=template.name
) }}
{% elif 'sms' == template_type %}
{{ sms_message(template.formatted_as_markup, name=template.name) }}
{% endif %}
</div>
<div class="column-one-third">
<div class="sms-message-use-links">
@@ -40,7 +49,7 @@
{% endif %}
<p>
<a href="{{ url_for('.add_service_template', service_id=service_id, template_type='sms') }}" class="button">Add a new template</a>
<a href="{{ url_for('.add_service_template', service_id=service_id, template_type=template_type) }}" class="button">Add a new template</a>
</p>
</form>

View File

@@ -14,13 +14,22 @@
{{ uploaded_file_name }}
</h1>
<div class="grid-row">
<div class="column-two-thirds">
{{ sms_message(
template.formatted_as_markup,
)}}
{% if 'sms' == template.template_type %}
<div class="grid-row">
<div class="column-two-thirds">
{{ sms_message(
template,
)}}
</div>
</div>
</div>
{% elif 'email' == template.template_type %}
{{ email_message(
template.subject,
template,
from_address='{}@notifications.service.gov.uk'.format(service.email_from),
from_name=service.name
)}}
{% endif %}
<p class='heading-small'>
Started {{ uploaded_file_time|format_datetime }}

View File

@@ -13,18 +13,23 @@
<h1 class="heading-large">Add recipients</h1>
{% if 'sms' == template.template_type %}
<div class="grid-row">
<div class="column-two-thirds">
{{ sms_message(template.formatted_as_markup) }}
</div>
</div>
{% elif 'email' == template.template_type %}
{{ email_message(
template.subject,
template.formatted_as_markup,
from_address='{}@notifications.service.gov.uk'.format(service.email_from),
from_name=service.name
) }}
{% endif %}
<div class="grid-row">
<div class="column-two-thirds">
{% if 'sms' == template.template_type %}
{{ sms_message(template.formatted_as_markup) }}
{% elif 'email' == template.template_type %}
{{ email_message(
template.subject,
template.formatted_as_markup,
from_address='{}@notifications.service.gov.uk'.format(service.email_from),
from_name=service.name
) }}
{% endif %}
{{ banner(
'You can upload real data, but well only send to your mobile number until you <a href="{}">request to go live</a>'.format(
url_for('.service_request_to_go_live', service_id=service_id)

View File

@@ -14,4 +14,4 @@ Pygments==2.0.2
git+https://github.com/alphagov/notifications-python-client.git@0.2.8#egg=notifications-python-client==0.2.8
git+https://github.com/alphagov/notifications-utils.git@0.1.1#egg=notifications-utils==0.1.1
git+https://github.com/alphagov/notifications-utils.git@0.1.2#egg=notifications-utils==0.1.2

View File

@@ -27,6 +27,7 @@ def test_should_show_page_for_one_job(app_,
mock_login,
mock_get_user,
mock_get_user_by_email,
mock_get_service,
mock_get_service_template,
job_data,
mock_get_job):