mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -04:00
Make message and recipient counters formatters
As formatters we can use them in Jinja or Python code. It also means we don’t need to import them every time we want to use them – they’re always available in the template context. For now this doesn’t remove the macros, it just aliases them to the formatters. This gives us confidence that the formatters are working the same way the old macros did, and reduces the diff size of each commit.
This commit is contained in:
@@ -1,79 +1,15 @@
|
||||
{% macro message_count_label(count, template_type, suffix='sent') -%}
|
||||
{% if template_type == None %}
|
||||
{%- if count == 1 -%}
|
||||
message
|
||||
{%- else -%}
|
||||
messages
|
||||
{%- endif -%}
|
||||
{% endif %}
|
||||
{%- if template_type == 'sms' -%}
|
||||
{%- if count == 1 -%}
|
||||
text message
|
||||
{%- else -%}
|
||||
text messages
|
||||
{%- endif -%}
|
||||
{%- elif template_type == 'email' -%}
|
||||
{%- if count == 1 -%}
|
||||
email
|
||||
{%- else -%}
|
||||
emails
|
||||
{%- endif -%}
|
||||
{%- elif template_type == 'letter' -%}
|
||||
{%- if count == 1 -%}
|
||||
letter
|
||||
{%- else -%}
|
||||
letters
|
||||
{%- endif -%}
|
||||
{%- elif template_type == 'broadcast' -%}
|
||||
{%- if count == 1 -%}
|
||||
broadcast
|
||||
{%- else -%}
|
||||
broadcasts
|
||||
{%- endif -%}
|
||||
{%- endif %} {{ suffix }}
|
||||
{{ count|message_count_noun(template_type) }} {{ suffix }}
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro recipient_count_label(count, template_type) -%}
|
||||
{% if template_type == None %}
|
||||
{%- if count == 1 -%}
|
||||
recipient
|
||||
{%- else -%}
|
||||
recipients
|
||||
{%- endif -%}
|
||||
{% endif %}
|
||||
{%- if template_type == 'sms' -%}
|
||||
{%- if count == 1 -%}
|
||||
phone number
|
||||
{%- else -%}
|
||||
phone numbers
|
||||
{%- endif -%}
|
||||
{%- elif template_type == 'email' -%}
|
||||
{%- if count == 1 -%}
|
||||
email address
|
||||
{%- else -%}
|
||||
email addresses
|
||||
{%- endif -%}
|
||||
{%- elif template_type == 'letter' -%}
|
||||
{%- if count == 1 -%}
|
||||
address
|
||||
{%- else -%}
|
||||
addresses
|
||||
{%- endif -%}
|
||||
{%- endif %}
|
||||
{{ count|recipient_count_label(template_type) }}
|
||||
{%- endmacro %}
|
||||
|
||||
|
||||
{% macro recipient_count(count, template_type, prefix='') -%}
|
||||
{{ count|format_thousands }} {{ prefix }} {{ recipient_count_label(count, template_type)}}
|
||||
{{ count|format_thousands }} {{ prefix }} {{ count|recipient_count_label(template_type) }}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro iteration_count(count) -%}
|
||||
{% if count == 1 %}
|
||||
once
|
||||
{% elif count == 2 %}
|
||||
twice
|
||||
{% else %}
|
||||
{{ count }} times
|
||||
{% endif %}
|
||||
{{ count|iteration_count }}
|
||||
{% endmacro %}
|
||||
|
||||
Reference in New Issue
Block a user