Try out previewing messages

This commit is contained in:
Chris Hill-Scott
2015-12-11 12:02:21 +00:00
parent 64f03bed06
commit 4c14e273c2
6 changed files with 40 additions and 11 deletions

View File

@@ -46,6 +46,7 @@ def create_app(config_name):
admin_api_client.init_app(application)
application.add_template_filter(placeholders)
application.add_template_filter(replace_placeholders)
return application
@@ -166,3 +167,13 @@ def placeholders(value):
lambda match: "<span class='placeholder'>{}</span>".format(match.group(1)),
value
))
def replace_placeholders(template, values):
if not template:
return template
return Markup(re.sub(
r"\(\(([^\)]+)\)\)", # anything that looks like ((registration number))
lambda match: values.get(match.group(1), ''),
template
))

View File

@@ -38,4 +38,10 @@
white-space: normal;
}
&-recipient {
@include copy-16;
color: $secondary-text-colour;
margin: 0;
}
}

View File

@@ -29,10 +29,9 @@
// Extra CSS for this application
@import "components/template-picker";
@import "components/sms-message";
@import "components/placeholder";
@import "components/sms-message";
@import "components/button";
@import "components/table";
// TODO: break this up into components
@import "app";

View File

@@ -36,11 +36,11 @@ def checksms():
return render_template(
'views/check-sms.html',
recipients=[
{'phone': "+44 7815838437", 'registration': 'LC12 BFL', 'date': '24 December 2015'},
{'phone': "+44 7815838437", 'registration': 'DU04 AOM', 'date': '25 December 2015'},
{'phone': "+44 7815838437", 'registration': 'M91 MJB', 'date': '26 December 2015'},
{'phone': "+44 7815838437", 'registration': 'Y249 NPU', 'date': '31 December 2015'},
{'phone': "+44 7815838437", 'registration': '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'}
],
message_template="""
Vehicle tax: Your vehicle tax for ((registration number)) expires on ((date)).

View File

@@ -1,4 +1,9 @@
{% macro sms_message(body) %}
{% macro sms_message(body, recipient) %}
{% if recipient %}
<p class="sms-message-recipient">
{{ recipient }}
</p>
{% endif %}
<div class="sms-message">
<div class="sms-message-wrapper">
{{ body|placeholders }}

View File

@@ -23,6 +23,14 @@
<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 %}
</div>
</div>
@@ -33,9 +41,9 @@
'Recipient', placeholder('registration number'), placeholder('date')
]
) %}
{% call field() %}{{item.phone}}{% endcall %}
{% call field() %}{{item.registration}}{% endcall %}
{% call field() %}{{item.date}}{% endcall %}
{% call field() %}{{item['phone']}}{% endcall %}
{% call field() %}{{item['registration number']}}{% endcall %}
{% call field() %}{{item['date']}}{% endcall %}
{% endcall %}
{% endblock %}