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:
Chris Hill-Scott
2021-01-06 12:59:48 +00:00
parent 7a95e1618e
commit 462294c9d1
3 changed files with 104 additions and 68 deletions

View File

@@ -62,8 +62,14 @@ from app.formatters import (
format_thousands,
format_time,
id_safe,
iteration_count,
linkable_name,
message_count,
message_count_label,
message_count_noun,
nl2br,
recipient_count,
recipient_count_label,
valid_phone_number,
)
from app.models.organisation import Organisation
@@ -548,6 +554,12 @@ def add_template_filters(application):
id_safe,
convert_to_boolean,
format_list_items,
iteration_count,
recipient_count,
recipient_count_label,
message_count_label,
message_count,
message_count_noun,
]:
application.add_template_filter(fn)