Do not create a new version of the template if there is no change to the tempalte.

This commit is contained in:
Rebecca Law
2016-06-01 10:53:03 +01:00
parent a97f3bbb4f
commit 0a9cdbd75a
3 changed files with 30 additions and 29 deletions

View File

@@ -59,14 +59,18 @@ def update_template(service_id, template_id):
fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id)
current_data = dict(template_schema.dump(fetched_template).data.items())
current_data.update(request.get_json())
current_data['content'] = _strip_html(current_data['content'])
update_template = dict(template_schema.dump(fetched_template).data.items())
update_template.update(request.get_json())
update_template['content'] = _strip_html(update_template['content'])
# Check if there is a change to make.
if current_data == update_template:
return jsonify(data=update_template), 200
update_dict, errors = template_schema.load(current_data)
update_dict, errors = template_schema.load(update_template)
if errors:
return jsonify(result="error", message=errors), 400
over_limit, json_resp = _content_count_greater_than_limit(
current_data['content'],
update_template['content'],
fetched_template.template_type)
if over_limit:
return json_resp, 400