From d2562889b85b7b9208505798562524093899727b Mon Sep 17 00:00:00 2001
From: Chris Hill-Scott
Date: Fri, 11 Dec 2015 13:52:58 +0000
Subject: [PATCH] Replace CSV preview with rendered messages
If there are less than 7 messages, show them all.
If there are more than 7, show the first and last three, and a link to the
remaining x.
---
.../stylesheets/components/sms-message.scss | 2 +-
app/assets/stylesheets/main.scss | 2 +-
app/main/views/sms.py | 69 +++++++++++--------
app/templates/views/check-sms.html | 59 ++++++++++------
app/templates/views/send-sms.html | 2 +-
5 files changed, 84 insertions(+), 50 deletions(-)
diff --git a/app/assets/stylesheets/components/sms-message.scss b/app/assets/stylesheets/components/sms-message.scss
index 04c33ef92..9263b8ec5 100644
--- a/app/assets/stylesheets/components/sms-message.scss
+++ b/app/assets/stylesheets/components/sms-message.scss
@@ -39,7 +39,7 @@
}
&-recipient {
- @include copy-16;
+ @include copy-19;
color: $secondary-text-colour;
margin: 0;
}
diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss
index bf736e788..3768fcce2 100644
--- a/app/assets/stylesheets/main.scss
+++ b/app/assets/stylesheets/main.scss
@@ -33,5 +33,5 @@
@import "components/sms-message";
@import "components/button";
@import "components/table";
-// TODO: break this up into components
+// TODO: break this up
@import "app";
diff --git a/app/main/views/sms.py b/app/main/views/sms.py
index cd5642190..891502fc5 100644
--- a/app/main/views/sms.py
+++ b/app/main/views/sms.py
@@ -3,28 +3,30 @@ from flask_login import login_required
from app.main import main
+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("/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
- """
- },
- ]
+ message_templates=message_templates
)
elif request.method == 'POST':
return redirect(url_for('.checksms'))
@@ -32,20 +34,33 @@ def sendsms():
@main.route("/sms/check", methods=['GET', 'POST'])
def checksms():
+
+ recipients = [
+ {'phone': "+44 7700 900989", 'registration number': 'LC12 BFL', 'date': '24 December 2015'},
+ {'phone': "+44 7700 900479", 'registration number': 'DU04 AOM', 'date': '25 December 2015'},
+ {'phone': "+44 7700 900964", 'registration number': 'M91 MJB', 'date': '26 December 2015'},
+ {'phone': "+44 7700 900703", 'registration number': 'Y249 NPU', 'date': '31 December 2015'},
+ {'phone': "+44 7700 900730", 'registration number': 'LG55 UGB', 'date': '1 January 2016'},
+ {'phone': "+44 7700 900989", 'registration number': 'LC12 BFL', 'date': '24 December 2015'},
+ {'phone': "+44 7700 900479", 'registration number': 'DU04 AOM', 'date': '25 December 2015'},
+ {'phone': "+44 7700 900964", 'registration number': 'M91 MJB', 'date': '26 December 2015'},
+ {'phone': "+44 7700 900703", 'registration number': 'Y249 NPU', 'date': '31 December 2015'},
+ {'phone': "+44 7700 900730", 'registration number': 'LG55 UGB', 'date': '1 January 2016'},
+ ]
+
+ number_of_recipients = len(recipients)
+ too_many_recipients_to_display = number_of_recipients > 7
+
if request.method == 'GET':
return render_template(
'views/check-sms.html',
- recipients=[
- {'phone': "+44 7700 900989", 'registration number': 'LC12 BFL', 'date': '24 December 2015'},
- {'phone': "+44 7700 900479", 'registration number': 'DU04 AOM', 'date': '25 December 2015'},
- {'phone': "+44 7700 900964", 'registration number': 'M91 MJB', 'date': '26 December 2015'},
- {'phone': "+44 7700 900703", 'registration number': 'Y249 NPU', 'date': '31 December 2015'},
- {'phone': "+44 7700 900730", 'registration number': '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
- """
+ number_of_recipients=number_of_recipients,
+ recipients={
+ "first_three": recipients[:3] if too_many_recipients_to_display else [],
+ "last_three": recipients[number_of_recipients - 3:] if too_many_recipients_to_display else [],
+ "all": recipients if not too_many_recipients_to_display else []
+ },
+ message_template=message_templates[0]['body']
)
elif request.method == 'POST':
return redirect(url_for('.showjob'))
diff --git a/app/templates/views/check-sms.html b/app/templates/views/check-sms.html
index 8a2a0eed9..91550665d 100644
--- a/app/templates/views/check-sms.html
+++ b/app/templates/views/check-sms.html
@@ -14,36 +14,55 @@
Send text messages
Check and confirm
- {{ sms_message(message_template) }}
- {% for recipient in recipients %}
- {{ sms_message(
- message_template|replace_placeholders(recipient),
- recipient['phone']
- ) }}
- {% endfor %}
+ {% if recipients.first_three and recipients.last_three %}
+
+ {% for recipient in recipients.first_three %}
+ {{ sms_message(
+ message_template|replace_placeholders(recipient),
+ "Row {} {}".format(loop.index, recipient['phone'])
+ ) }}
+ {% endfor %}
+
+
+ See rows 4 to {{ number_of_recipients - 3 }}
+
+
+ {% for recipient in recipients.last_three %}
+ {{ sms_message(
+ message_template|replace_placeholders(recipient),
+ "Row {} {}".format(number_of_recipients - 3 + loop.index, recipient['phone'])
+ ) }}
+ {% endfor %}
+
+ {% else %}
+
+ {% for recipient in recipients.all %}
+ {{ sms_message(
+ message_template|replace_placeholders(recipient),
+ "Row {} {}".format(loop.index, recipient['phone'])
+ ) }}
+ {% endfor %}
+
+ {% endif %}
+
+
+
+
- {% call(item) table(
- recipients,
- caption="Preview of the first 3 recipients",
- field_headings=[
- 'Recipient', placeholder('registration number'), placeholder('date')
- ]
- ) %}
- {% call field() %}{{item['phone']}}{% endcall %}
- {% call field() %}{{item['registration number']}}{% endcall %}
- {% call field() %}{{item['date']}}{% endcall %}
- {% endcall %}
-
{% endblock %}
diff --git a/app/templates/views/send-sms.html b/app/templates/views/send-sms.html
index 26f6a513e..24602c2b0 100644
--- a/app/templates/views/send-sms.html
+++ b/app/templates/views/send-sms.html
@@ -24,7 +24,7 @@
{% endfor %}
- Or create a new template
+ or create a new template
2. Add recipients