From 72742cf47707d6df764fa4264aa49afffd8153dc Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 11 Oct 2021 15:24:55 +0100 Subject: [PATCH] Move unknown organisation logic into Jinja MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Human readable content like this doesn’t really belong in the model layer, it’s more natural to have it in the presentation layer. --- app/formatters.py | 6 ++++-- app/models/organisation.py | 15 --------------- app/templates/go-live-request.txt | 2 +- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/app/formatters.py b/app/formatters.py index eb275cfc1..aa8d42663 100644 --- a/app/formatters.py +++ b/app/formatters.py @@ -520,5 +520,7 @@ def format_billions(count): return humanize.intword(count) -def format_yes_no(value): - return 'Yes' if value else 'No' +def format_yes_no(value, yes='Yes', no='No', none='No'): + if value is None: + return none + return yes if value else no diff --git a/app/models/organisation.py b/app/models/organisation.py index 7d91aa84d..5b5e5272a 100644 --- a/app/models/organisation.py +++ b/app/models/organisation.py @@ -101,21 +101,6 @@ class Organisation(JSONModel): self.request_to_go_live_notes = None self.email_branding_id = None - @property - def as_agreement_statement_for_go_live_request(self): - return '{} (organisation is {}, {}).'.format( - { - False: 'No', - None: 'Can’t tell', - }.get(self.agreement_signed), - self.name, - { - True: 'a crown body', - False: 'a non-crown body', - None: 'crown status unknown', - }.get(self.crown), - ) - def as_info_for_branding_request(self, fallback_domain): return self.name or 'Can’t tell (domain is {})'.format(fallback_domain) diff --git a/app/templates/go-live-request.txt b/app/templates/go-live-request.txt index ce70e8d68..7f6296d30 100644 --- a/app/templates/go-live-request.txt +++ b/app/templates/go-live-request.txt @@ -5,7 +5,7 @@ Service: {{ current_service.name }} Organisation type: {{ current_service.organisation_type_label }} Agreement signed: {%- if current_service.organisation.agreement_signed %} Yes, on behalf of {{ current_service.organisation.name }}. -{%- elif current_service.organisation.name %} {{ current_service.organisation.as_agreement_statement_for_go_live_request }} +{%- elif current_service.organisation.name %} {{ current_service.organisation.agreement_signed|format_yes_no(none='Can’t tell') }} (organisation is {{ current_service.organisation.name }}, {{ current_service.organisation.crown|format_yes_no(yes='a crown body', no='a non-crown body', none='crown status unknown') }}). {%- else %} Can’t tell (domain is {{ current_user.email_domain }}). {%- endif %} {%- if current_service.organisation.request_to_go_live_notes %} {{ current_service.organisation.request_to_go_live_notes }}{% endif %}