def copy_template(service_id, template_id): from_service = request.args.get('from_service') current_user.belongs_to_service_or_403(from_service) template = service_api_client.get_service_template(from_service, template_id)['data'] template_folder = template_folder_api_client.get_template_folder( from_service, template['folder']) if not current_user.has_template_folder_permission(template_folder): abort(403) if request.method == 'POST': return add_service_template(service_id, template['template_type']) template['template_content'] = template['content'] template['name'] = _get_template_copy_name(template, current_service.all_templates) form = form_objects[template['template_type']](**template) return render_template( 'views/edit-{}-template.html'.format(template['template_type']), form=form, template=template, heading_action='Add', services=current_user.service_ids, )
def copy_template(service_id, template_id): from_service = request.args.get("from_service") current_user.belongs_to_service_or_403(from_service) template = service_api_client.get_service_template( from_service, str(template_id))["data"] template_folder = template_folder_api_client.get_template_folder( from_service, template["folder"]) if not current_user.has_template_folder_permission(template_folder): abort(403) if request.method == "POST": return add_service_template( service_id, template["template_type"], template_folder_id=template_folder.get("id"), ) template["template_content"] = template["content"] template["name"] = _get_template_copy_name(template, current_service.all_templates) form = form_objects[template["template_type"]](**template) return render_template( f"views/edit-{template['template_type']}-template.html", form=form, template=template, heading=_l("Copy email template") if template["template_type"] == "email" else _l("Copy text message template"), service_id=service_id, services=current_user.service_ids, )