Refactor organisation branding into model

This is the same way we handle lazy-loading the branding in the service
model.
This commit is contained in:
Chris Hill-Scott
2019-09-12 11:49:31 +01:00
parent e18e2d1e98
commit 29a0611e42
3 changed files with 24 additions and 19 deletions

View File

@@ -2,6 +2,8 @@ from flask import abort
from werkzeug.utils import cached_property
from app.models import JSONModel, ModelList
from app.notify_client.email_branding_client import email_branding_client
from app.notify_client.letter_branding_client import letter_branding_client
from app.notify_client.organisations_api_client import organisations_client
@@ -148,6 +150,26 @@ class Organisation(JSONModel):
key=lambda user: user.email_address.lower(),
)
@cached_property
def email_branding(self):
if self.email_branding_id:
return email_branding_client.get_email_branding(
self.email_branding_id
)['email_branding']
@property
def email_branding_name(self):
if self.email_branding_id:
return self.email_branding['name']
return 'GOV.UK'
@cached_property
def letter_branding(self):
if self.letter_branding_id:
return letter_branding_client.get_letter_branding(
self.letter_branding_id
)
def update(self, **kwargs):
response = organisations_client.update_organisation(self.id, **kwargs)
self.__init__(response)