Change postage while editing template

This commit is contained in:
Pea Tyczynska
2018-12-18 18:22:03 +00:00
parent a60d269900
commit 687e9e5866
4 changed files with 37 additions and 5 deletions

View File

@@ -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',

View File

@@ -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',

View File

@@ -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)

View File

@@ -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 @@
<div class="grid-row">
<div class="column-five-sixths">
{{ textbox(form.name, width='1-1', hint='Your recipients wont 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(