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.
This commit is contained in:
Chris Hill-Scott
2015-12-11 13:52:58 +00:00
parent 4c14e273c2
commit d2562889b8
5 changed files with 84 additions and 50 deletions

View File

@@ -39,7 +39,7 @@
}
&-recipient {
@include copy-16;
@include copy-19;
color: $secondary-text-colour;
margin: 0;
}

View File

@@ -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";

View File

@@ -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'))

View File

@@ -14,36 +14,55 @@
<h1 class="heading-xlarge">Send text messages</h1>
<h2 class="heading-medium">Check and confirm</h2>
{{ sms_message(message_template) }}
<p>
<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" />
<input type="submit" class="button" value="Send {{ number_of_recipients }} text messages" />
<a class="button-secondary" role="button" href="{{ url_for(".sendsms") }}">Back</a>
</form>
</p>
{% 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 %}
<p>
<a href="#">See rows 4 to {{ number_of_recipients - 3 }}</a>
</p>
{% 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 %}
<p>
<form method="POST" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="submit" class="button" value="Send {{ number_of_recipients }} text messages" />
<a class="button-secondary" role="button" href="{{ url_for(".sendsms") }}">Back</a>
</form>
</p>
</div>
</div>
{% 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 %}

View File

@@ -24,7 +24,7 @@
{% endfor %}
<p>
<a href="{{ url_for(".managetemplates") }}">Or create a new template</a>
or <a href="{{ url_for(".managetemplates") }}">create a new template</a>
</p>
<h2 class="heading-medium">2. Add recipients</h2>