From 687e9e5866e43585b4978448ba7de9dfe05b59c2 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Tue, 18 Dec 2018 18:22:03 +0000 Subject: [PATCH] Change postage while editing template --- app/main/forms.py | 10 +++++++++ app/main/views/templates.py | 22 +++++++++++++++---- app/notify_client/service_api_client.py | 6 ++++- app/templates/views/edit-letter-template.html | 4 ++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index ccb11dae5..b8f95bab4 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -447,6 +447,16 @@ class EmailTemplateForm(BaseTemplateForm): class LetterTemplateForm(EmailTemplateForm): + postage = RadioField( + 'Choose postage', + choices=[ + ('first', 'First class'), + ('second', 'Second class'), + ('service_default', "Service default"), + ], + validators=[DataRequired()], + default='service_default' + ) subject = TextAreaField( u'Main heading', diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 8c2fda7ab..998e8971e 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -571,15 +571,27 @@ def edit_service_template(service_id, template_id): abort_403_if_not_admin_user() subject = form.subject.data if hasattr(form, 'subject') else None - new_template = get_template({ + + new_template_data = { 'name': form.name.data, 'content': form.template_content.data, 'subject': subject, 'template_type': template['template_type'], 'id': template['id'], 'process_type': form.process_type.data, - 'reply_to_text': template['reply_to_text'] - }, current_service) + 'reply_to_text': template['reply_to_text'], + } + if ( + current_service.has_permission("choose_postage") and template["template_type"] == "letter" + ) and form.postage.data in ["first", "second"]: + postage = {"postage": form.postage.data } + + else: + postage = {} + + new_template_data.update(postage) + + new_template = get_template(new_template_data, current_service) template_change = get_template(template, current_service).compare_to(new_template) if template_change.placeholders_added and not request.form.get('confirm'): example_column_headings = ( @@ -606,7 +618,8 @@ def edit_service_template(service_id, template_id): form.template_content.data, service_id, subject, - form.process_type.data + form.process_type.data, + postage=postage.get("postage") ) except HTTPError as e: if e.status_code == 400: @@ -637,6 +650,7 @@ def edit_service_template(service_id, template_id): return render_template( 'views/edit-{}-template.html'.format(template['template_type']), form=form, + can_choose_postage=current_service.has_permission("choose_postage"), template_id=template_id, template_type=template['template_type'], heading_action='Edit', diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 7af14425f..75485e745 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -153,7 +153,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): @cache.delete('service-{service_id}-templates') @cache.delete('template-{id_}-version-None') @cache.delete('template-{id_}-versions') - def update_service_template(self, id_, name, type_, content, service_id, subject=None, process_type=None): + def update_service_template(self, id_, name, type_, content, service_id, subject=None, process_type=None, postage=None): """ Update a service template. """ @@ -172,6 +172,10 @@ class ServiceAPIClient(NotifyAdminAPIClient): data.update({ 'process_type': process_type }) + if postage: + data.update({ + 'postage': postage + }) data = _attach_current_user(data) endpoint = "/service/{0}/template/{1}".format(service_id, id_) return self.post(endpoint, data) diff --git a/app/templates/views/edit-letter-template.html b/app/templates/views/edit-letter-template.html index 4d0c62163..353ae4721 100644 --- a/app/templates/views/edit-letter-template.html +++ b/app/templates/views/edit-letter-template.html @@ -1,6 +1,7 @@ {% extends "withnav_template.html" %} {% from "components/textbox.html" import textbox %} {% from "components/page-footer.html" import page_footer %} +{% from "components/radios.html" import radios %} {% from "components/form.html" import form_wrapper %} {% block service_page_title %} @@ -17,6 +18,9 @@
{{ textbox(form.name, width='1-1', hint='Your recipients won’t see this', rows=10) }} + {% if can_choose_postage %} + {{ radios(form.postage, hint='Go to Settings to change default postage for your service') }} + {% endif %} {{ textbox(form.subject, width='1-1', highlight_tags=True, rows=2) }} {{ textbox(form.template_content, highlight_tags=True, width='1-1', rows=8) }} {{ page_footer(