Consolidate page templates for emails + texts

Use one page template for each of:
- choosing a message template
- adding recipients
- checking an email message
- looking at a job

This commit consolidates the two templates into one, and adds logic to show
the SMS message pattern or the email message pattern depending on the type of
template.

It also gives email templates a bit more width, because the body and the from
address tend to be quite long.
This commit is contained in:
Chris Hill-Scott
2016-02-25 16:37:39 +00:00
parent 2c4119e2e0
commit a51d92c87a
9 changed files with 80 additions and 90 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 = []
@@ -58,7 +60,8 @@ def view_job(service_id, job_id):
template=Template(
templates_dao.get_service_template_or_404(service_id, job['template'])['data']
),
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,14 @@ 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']
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
)
@@ -130,6 +138,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)
@@ -144,14 +153,16 @@ def check_messages(service_id, upload_id):
drop_values={'to'}
)
return render_template(
'views/check-sms.html',
'views/check.html',
upload_result=upload_result,
template=template,
page_heading=page_headings[template.template_type],
column_headers=['to'] + list(
template.placeholders if upload_result['valid'] else 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 +204,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