From c9a32c73272f6a58da5c638fcf874c911ef4290c Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 27 Aug 2019 16:32:30 +0100 Subject: [PATCH] Remove duplication of org type lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s a couple of places where we’re looking up the label for the type of organisation. Having this repeated in multiple places means it’s more likely we forget to update one of these places when making a change. This commit looks up from the tuple in the organisation model, which is where other code references this stuff from. This is only possible now that we don’t have duplicate keys (ie GP practice doesn’t share a key any more). --- app/models/organisation.py | 4 ++++ app/models/service.py | 4 ++++ .../organisations/organisation/settings/index.html | 10 +--------- app/templates/views/service-settings.html | 12 ++---------- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/models/organisation.py b/app/models/organisation.py index 7ca83be26..e617e295a 100644 --- a/app/models/organisation.py +++ b/app/models/organisation.py @@ -109,6 +109,10 @@ class Organisation(JSONModel): def as_info_for_branding_request(self, fallback_domain): return self.name or 'Can’t tell (domain is {})'.format(fallback_domain) + @property + def organisation_type_label(self): + return dict(self.TYPES).get(self.organisation_type) + @property def crown_status_or_404(self): if self.crown is None: diff --git a/app/models/service.py b/app/models/service.py index f9dc2706b..5d4ce1df8 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -439,6 +439,10 @@ class Service(JSONModel): def organisation_type(self): return self.organisation.organisation_type or self._dict['organisation_type'] + @property + def organisation_type_label(self): + return dict(Organisation.TYPES).get(self.organisation_type) + @cached_property def inbound_number(self): return inbound_number_client.get_inbound_sms_number_for_service(self.id)['data'].get('number', '') diff --git a/app/templates/views/organisations/organisation/settings/index.html b/app/templates/views/organisations/organisation/settings/index.html index f45a6997e..793274947 100644 --- a/app/templates/views/organisations/organisation/settings/index.html +++ b/app/templates/views/organisations/organisation/settings/index.html @@ -25,15 +25,7 @@ {% endcall %} {% call row() %} {{ text_field('Sector') }} - {{ optional_text_field({ - 'central': 'Central government', - 'local': 'Local government', - 'nhs_central': 'NHS – central government agency or public body', - 'nhs_local': 'NHS Trust, GP practice or Clinical Commissioning Group', - 'emergency_service': 'Emergency service', - 'school_or_college': 'School or college', - 'other': 'Other', - }.get(current_org.organisation_type)) }} + {{ optional_text_field(current_org.organisation_type_label) }} {{ edit_field( 'Change', url_for('.edit_organisation_type', org_id=current_org.id) diff --git a/app/templates/views/service-settings.html b/app/templates/views/service-settings.html index 60d6b7acc..6f4febc85 100644 --- a/app/templates/views/service-settings.html +++ b/app/templates/views/service-settings.html @@ -260,7 +260,7 @@

{% if current_user.has_permissions('manage_service') %} - To remove these restrictions, you can send us a + To remove these restrictions, you can send us a request to go live. {% else %} Your service manager can ask to have these restrictions removed. @@ -324,15 +324,7 @@ {% endif %} {% if current_service.organisation_type %}

- {{ { - 'central': 'Central government', - 'local': 'Local government', - 'nhs_central': 'NHS – central government agency or public body', - 'nhs_local': 'NHS Trust, GP practice or Clinical Commissioning Group', - 'emergency_service': 'Emergency service', - 'school_or_college': 'School or college', - 'other': 'Other' - }.get(current_service.organisation_type) }} + {{ current_service.organisation_type_label }}
{% endif %} {% endcall %}