diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 7b2794eb8..849cb2e5e 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -25,6 +25,7 @@ from app.main.forms import ( SMSTemplateForm, ) from app.main.views.send import get_example_csv_rows, get_sender_details +from app.models.service import Service from app.template_previews import TemplatePreview, get_page_count_for_letter from app.utils import ( email_or_sms_not_enabled, @@ -231,15 +232,10 @@ def add_template_by_type(service_id): def choose_template_to_copy(service_id): return render_template( 'views/templates/copy.html', - services=[{ - 'name': service['name'], - 'id': service['id'], - 'templates': [ - template for template in - service_api_client.get_service_templates(service['id'])['data'] - if current_service.has_permission(template['template_type']) - ], - } for service in user_api_client.get_services_for_user(current_user)], + services=[ + Service(service) + for service in user_api_client.get_services_for_user(current_user) + ], ) diff --git a/app/models/service.py b/app/models/service.py index 1682045dc..953cd3538 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -81,9 +81,11 @@ class Service(): ] def templates_by_type(self, template_type): + if isinstance(template_type, str): + template_type = [template_type] return [ template for template in self.templates - if template_type in {'all', template['template_type']} + if set(template_type) & {'all', template['template_type']} ] @property diff --git a/app/templates/views/templates/copy.html b/app/templates/views/templates/copy.html index 8690b4b2c..94d765f05 100644 --- a/app/templates/views/templates/copy.html +++ b/app/templates/views/templates/copy.html @@ -13,13 +13,14 @@