diff --git a/app/__init__.py b/app/__init__.py index f3af80102..cc3705a93 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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: "{}".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 + )) diff --git a/app/assets/stylesheets/components/sms-message.scss b/app/assets/stylesheets/components/sms-message.scss index 83176f2ed..04c33ef92 100644 --- a/app/assets/stylesheets/components/sms-message.scss +++ b/app/assets/stylesheets/components/sms-message.scss @@ -38,4 +38,10 @@ white-space: normal; } + &-recipient { + @include copy-16; + color: $secondary-text-colour; + margin: 0; + } + } diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index 2c599e5ca..bf736e788 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -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"; diff --git a/app/main/views/sms.py b/app/main/views/sms.py index 6322c92d4..cd5642190 100644 --- a/app/main/views/sms.py +++ b/app/main/views/sms.py @@ -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)). diff --git a/app/templates/components/sms-message.html b/app/templates/components/sms-message.html index 2b794ba68..5d5f11d12 100644 --- a/app/templates/components/sms-message.html +++ b/app/templates/components/sms-message.html @@ -1,4 +1,9 @@ -{% macro sms_message(body) %} +{% macro sms_message(body, recipient) %} + {% if recipient %} +

+ {{ recipient }} +

+ {% endif %}
{{ body|placeholders }} diff --git a/app/templates/views/check-sms.html b/app/templates/views/check-sms.html index 7c96ac7b8..8a2a0eed9 100644 --- a/app/templates/views/check-sms.html +++ b/app/templates/views/check-sms.html @@ -23,6 +23,14 @@ Back

+ + {% for recipient in recipients %} + {{ sms_message( + message_template|replace_placeholders(recipient), + recipient['phone'] + ) }} + {% endfor %} +
@@ -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 %}