Merge pull request #2616 from alphagov/choose_postage

Choose and display postage on template
This commit is contained in:
Pea (Malgorzata Tyczynska)
2019-01-02 15:39:15 +00:00
committed by GitHub
12 changed files with 226 additions and 24 deletions

View File

@@ -76,6 +76,7 @@ def view_template(service_id, template_id):
show_recipient=True,
page_count=get_page_count_for_letter(template),
),
template_postage=template["postage"],
default_letter_contact_block_id=default_letter_contact_block_id,
)
@@ -570,21 +571,29 @@ def edit_service_template(service_id, template_id):
template = service_api_client.get_service_template(service_id, template_id)['data']
template['template_content'] = template['content']
form = form_objects[template['template_type']](**template)
if form.validate_on_submit():
if form.process_type.data != template['process_type']:
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":
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 = (
@@ -611,7 +620,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:
@@ -642,6 +652,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',