Add a formatter for yes/no

This is a bit neater than a bunch of repetetive ternary statements.
This commit is contained in:
Chris Hill-Scott
2021-10-11 14:26:46 +01:00
parent f85ee3dd0a
commit fad3ff70f2
3 changed files with 8 additions and 2 deletions

View File

@@ -62,6 +62,7 @@ from app.formatters import (
format_number_in_pounds_as_currency,
format_thousands,
format_time,
format_yes_no,
id_safe,
iteration_count,
linkable_name,
@@ -567,6 +568,7 @@ def add_template_filters(application):
message_count,
message_count_noun,
format_mobile_network,
format_yes_no,
]:
application.add_template_filter(fn)

View File

@@ -518,3 +518,7 @@ def format_mobile_network(network):
def format_billions(count):
return humanize.intword(count)
def format_yes_no(value):
return 'Yes' if value else 'No'

View File

@@ -9,8 +9,8 @@ Emails in next year: {{ current_service.volume_email|format_thousands }}
Text messages in next year: {{ current_service.volume_sms|format_thousands }}
Letters in next year: {{ current_service.volume_letter|format_thousands }}
Consent to research: {{ "Yes" if current_service.consent_to_research else "No" }}
Other live services for that user: {{ "Yes" if current_user.live_services else "No" }}
Consent to research: {{ current_service.consent_to_research|format_yes_no }}
Other live services for that user: {{ current_user.live_services|format_yes_no }}
Service reply-to address: {{ current_service.default_email_reply_to_address or "not set" }}