Merge pull request #2488 from alphagov/copy-template-name

Put ‘copy’ at end of new template name
This commit is contained in:
Chris Hill-Scott
2018-11-20 14:14:09 +00:00
committed by GitHub
2 changed files with 49 additions and 2 deletions

View File

@@ -318,7 +318,7 @@ def copy_template(service_id, template_id):
return add_service_template(service_id, template['template_type'])
template['template_content'] = template['content']
template['name'] = 'Copy of {}'.format(template['name'])
template['name'] = _get_template_copy_name(template, current_service.all_templates)
form = form_objects[template['template_type']](**template)
return render_template(
@@ -330,6 +330,20 @@ def copy_template(service_id, template_id):
)
def _get_template_copy_name(template, existing_templates):
template_names = [existing['name'] for existing in existing_templates]
for index in reversed(range(1, 10)):
if '{} (copy {})'.format(template['name'], index) in template_names:
return '{} (copy {})'.format(template['name'], index + 1)
if '{} (copy)'.format(template['name']) in template_names:
return '{} (copy 2)'.format(template['name'])
return '{} (copy)'.format(template['name'])
@main.route("/services/<service_id>/templates/action-blocked/<notification_type>/<return_to>/<template_id>")
@login_required
@user_has_permissions('manage_templates')