use new letter branding instead of dvla organisation id

new code is copied stylistically from the email branding patterns.
Instead of `service.dvla_organisation`, there's now
`service.letter_branding` and `service.letter_branding_id`. However,
unlike email branding we're not currently showing a preview of the
logo. That can come later when we work out how we want to do it.
This commit is contained in:
Leo Hemsted
2019-02-01 16:34:54 +00:00
parent 0e20ca44a3
commit a1caf77b0e
7 changed files with 49 additions and 19 deletions

View File

@@ -807,6 +807,11 @@ class ServiceSetEmailBranding(StripWhitespaceForm):
) )
class ServiceSetLetterBranding(ServiceSetEmailBranding):
# form is the same, but instead of GOV.UK we have None as a valid option
DEFAULT = (FieldWithNoneOption.NONE_OPTION_VALUE, 'None')
class ServicePreviewBranding(StripWhitespaceForm): class ServicePreviewBranding(StripWhitespaceForm):
branding_style = HiddenFieldWithNoneOption('branding_style') branding_style = HiddenFieldWithNoneOption('branding_style')

View File

@@ -46,6 +46,7 @@ from app.main.forms import (
ServicePreviewBranding, ServicePreviewBranding,
ServiceReplyToEmailForm, ServiceReplyToEmailForm,
ServiceSetEmailBranding, ServiceSetEmailBranding,
ServiceSetLetterBranding,
ServiceSmsSenderForm, ServiceSmsSenderForm,
ServiceSwitchChannelForm, ServiceSwitchChannelForm,
SMSPrefixForm, SMSPrefixForm,
@@ -805,16 +806,17 @@ def service_preview_email_branding(service_id):
@main.route("/services/<service_id>/service-settings/set-letter-branding", methods=['GET', 'POST']) @main.route("/services/<service_id>/service-settings/set-letter-branding", methods=['GET', 'POST'])
@login_required @login_required
@user_is_platform_admin @user_is_platform_admin
def set_letter_branding(service_id): def service_set_letter_branding(service_id):
letter_branding = letter_branding_client.get_all_letter_branding()
form = LetterBranding( form = ServiceSetLetterBranding(
choices=letter_branding_client.get_letter_branding().items(), all_branding_options=get_branding_as_value_and_label(letter_branding),
dvla_org_id=current_service.dvla_organisation, current_branding=current_service.letter_branding_id,
) )
if form.validate_on_submit(): if form.validate_on_submit():
current_service.update( current_service.update(
dvla_organisation=form.dvla_org_id.data letter_branding=form.branding_style.data
) )
return redirect(url_for('.service_settings', service_id=service_id)) return redirect(url_for('.service_settings', service_id=service_id))
@@ -822,6 +824,7 @@ def set_letter_branding(service_id):
'views/service-settings/set-letter-branding.html', 'views/service-settings/set-letter-branding.html',
form=form, form=form,
search_form=SearchTemplatesForm(), search_form=SearchTemplatesForm(),
show_search_box=(len(letter_branding) > 6)
) )

View File

@@ -28,6 +28,7 @@ class Service():
'email_from', 'email_from',
'id', 'id',
'inbound_api', 'inbound_api',
'letter_branding',
'letter_contact_block', 'letter_contact_block',
'letter_logo_filename', 'letter_logo_filename',
'message_limit', 'message_limit',
@@ -303,11 +304,15 @@ class Service():
return email_branding_client.get_email_branding(self.email_branding_id)['email_branding'] return email_branding_client.get_email_branding(self.email_branding_id)['email_branding']
return None return None
@property
def letter_branding_id(self):
return self._dict['letter_branding']
@cached_property @cached_property
def letter_branding(self): def letter_branding(self):
return letter_branding_client.get_letter_branding().get( if self.letter_branding_id:
self.dvla_organisation, '001' return letter_branding_client.get_letter_branding(self.letter_branding_id)
) return None
@cached_property @cached_property
def organisation_name(self): def organisation_name(self):

View File

@@ -1,10 +1,24 @@
from app.notify_client import NotifyAdminAPIClient from app.notify_client import NotifyAdminAPIClient, cache
class LetterBrandingClient(NotifyAdminAPIClient): class LetterBrandingClient(NotifyAdminAPIClient):
def get_letter_branding(self): @cache.set('letter_branding-{branding_id}')
return self.get(url='/dvla_organisations') def get_letter_branding(self, branding_id):
return self.get(url='/letter-branding/{}'.format(branding_id))
@cache.set('letter_branding')
def get_all_letter_branding(self, sort_key=None):
brandings = self.get(url='/letter-branding')
if sort_key and sort_key in brandings[0]:
brandings.sort(key=lambda branding: branding[sort_key].lower())
return brandings
def get_letter_branding_id_for_domain(self, domain):
for branding in self.get_all_letter_branding():
if domain and branding.get('domain') == domain:
return branding['id']
return None
def create_letter_branding(self, filename, name, domain): def create_letter_branding(self, filename, name, domain):
data = { data = {

View File

@@ -75,6 +75,7 @@ class ServiceAPIClient(NotifyAdminAPIClient):
'sms_sender', 'sms_sender',
'created_by', 'created_by',
'branding', 'branding',
'letter_branding',
'email_branding', 'email_branding',
'letter_contact_block', 'letter_contact_block',
'dvla_organisation', 'dvla_organisation',

View File

@@ -309,8 +309,8 @@
{% endcall %} {% endcall %}
{% call row() %} {% call row() %}
{{ text_field('Letter branding')}} {{ text_field('Letter branding')}}
{{ text_field(current_service.letter_branding) }} {{ text_field(current_service.letter_branding.name) }}
{{ edit_field('Change', url_for('.set_letter_branding', service_id=current_service.id)) }} {{ edit_field('Change', url_for('.service_set_letter_branding', service_id=current_service.id)) }}
{% endcall %} {% endcall %}
{% call row() %} {% call row() %}
{{ text_field('Data retention')}} {{ text_field('Data retention')}}

View File

@@ -13,12 +13,14 @@
<h1 class="heading-large">Set letter branding</h1> <h1 class="heading-large">Set letter branding</h1>
{% call form_wrapper() %} {% call form_wrapper() %}
{{ live_search(target_selector='.multiple-choice', show=True, form=search_form, label='Search by name') }} {{ live_search(target_selector='.multiple-choice', show=True, form=search_form, label='Search by name') }}
{{ radios(form.dvla_org_id, hide_legend=True) }} {{ radios(form.branding_style, hide_legend=True) }}
{{ page_footer( <div class="js-stick-at-bottom-when-scrolling">
'Save', {{ page_footer(
back_link=url_for('.service_settings', service_id=current_service.id), 'Save',
back_link_text='Back to settings' back_link=url_for('.service_settings', service_id=current_service.id),
) }} back_link_text='Back to settings'
) }}
</div>
{% endcall %} {% endcall %}
{% endblock %} {% endblock %}