Add a page to set organisation and branding option

Platform admin only.

Adds radio buttons to choose one of:
- three hard-coded branding options
- organisations from a list provided by the API
This commit is contained in:
Chris Hill-Scott
2016-08-08 10:28:40 +01:00
committed by Leo Hemsted
parent 20c39d24b7
commit 6b5e64479a
10 changed files with 249 additions and 6 deletions

View File

@@ -338,3 +338,29 @@ class ServiceSmsSender(Form):
import re
if field.data and not re.match('^[a-zA-Z0-9\s]+$', field.data):
raise ValidationError('Sms text message sender can only contain alpha-numeric characters')
class ServiceBrandingOrg(Form):
def __init__(self, organisations=[], *args, **kwargs):
self.organisation.choices = organisations
super(ServiceBrandingOrg, self).__init__(*args, **kwargs)
branding_type = RadioField(
'Branding',
choices=[
('govuk', 'GOV.UK only'),
('both', 'GOV.UK and organisation'),
('org', 'Organisation only')
],
validators=[
DataRequired()
]
)
organisation = RadioField(
'Organisation',
validators=[
DataRequired()
]
)

View File

@@ -24,10 +24,10 @@ from app.main.forms import (
ServiceNameForm,
RequestToGoLiveForm,
ServiceReplyToEmailFrom,
ServiceSmsSender
ServiceSmsSender,
ServiceBrandingOrg
)
from app import user_api_client
from app import current_service
from app import user_api_client, current_service, organisations_client
@main.route("/services/<service_id>/service-settings")
@@ -266,3 +266,50 @@ def service_set_sms_sender(service_id):
return render_template(
'views/service-settings/set-sms-sender.html',
form=form)
@main.route("/services/<service_id>/service-settings/set-branding-and-org", methods=['GET', 'POST'])
@login_required
@user_has_permissions(admin_override=True)
def service_set_branding_and_org(service_id):
print(">>>"*30)
print("fffffuuuuu")
organisations = organisations_client.get_organisations()
# get current service branding
form = ServiceBrandingOrg(
branding_type=current_service.get('branding'),
organisation=current_service.get('organisation')
)
form.organisation.choices = [('', 'None')] + get_branding_as_value_and_label(organisations)
if form.validate_on_submit():
service_api_client.update_service(
service_id,
branding=form.branding_type.data,
organisation=form.organisation.data
)
return redirect(url_for('.service_settings', service_id=service_id))
return render_template(
'views/service-settings/set-branding-and-org.html',
form=form,
branding_dict=get_branding_as_dict(organisations)
)
def get_branding_as_value_and_label(organisations):
return [
(organisation['id'], organisation['name'])
for organisation in organisations
]
def get_branding_as_dict(organisations):
return {
organisation['id']: {
'logo': '/static/images/email-template/crests/{}'.format(organisation['logo']),
'colour': organisation['colour']
} for organisation in organisations
}