diff --git a/app/main/views/conversation.py b/app/main/views/conversation.py index 540945afb..abe71fc3a 100644 --- a/app/main/views/conversation.py +++ b/app/main/views/conversation.py @@ -44,7 +44,7 @@ def conversation_reply( service_id, notification_id, ): - templates = current_service.templates_by_type('sms') + templates = current_service.get_templates('sms') return render_template( 'views/templates/choose-reply.html', templates=templates, diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 67973ad13..608be319d 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -118,11 +118,11 @@ def choose_template(service_id, template_type='all'): return render_template( 'views/templates/choose.html', template_folders=current_service.template_folders, - templates=current_service.templates_by_type(template_type), - show_search_box=(len(current_service.templates_by_type(template_type)) > 7), + templates=current_service.get_templates(template_type), + show_search_box=(len(current_service.get_templates(template_type)) > 7), show_template_nav=( current_service.has_multiple_template_types - and (len(current_service.templates) > 2) + and (len(current_service.all_templates) > 2) ), template_nav_items=template_nav_items, template_type=template_type, diff --git a/app/models/service.py b/app/models/service.py index 18c53aae9..ddd37d807 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -68,7 +68,7 @@ class Service(): ) > 1 @cached_property - def templates(self): + def all_templates(self): templates = service_api_client.get_service_templates(self.id)['data'] @@ -77,12 +77,14 @@ class Service(): if template['template_type'] in self.available_template_types ] - def templates_by_type(self, template_type): + def get_templates(self, template_type='all', template_folder_id=None): if isinstance(template_type, str): template_type = [template_type] + return [ - template for template in self.templates - if set(template_type) & {'all', template['template_type']} + template for template in self.all_templates + if (set(template_type) & {'all', template['template_type']}) + and template.get('folder_id') == template_folder_id ] @property @@ -94,21 +96,21 @@ class Service(): @property def has_templates(self): - return len(self.templates) > 0 + return len(self.all_templates) > 0 @property def has_multiple_template_types(self): return len({ - template['template_type'] for template in self.templates + template['template_type'] for template in self.all_templates }) > 1 @property def has_email_templates(self): - return len(self.templates_by_type('email')) > 0 + return len(self.get_templates('email')) > 0 @property def has_sms_templates(self): - return len(self.templates_by_type('sms')) > 0 + return len(self.get_templates('sms')) > 0 @cached_property def email_reply_to_addresses(self): diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 3ddcc0f39..e480efe95 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -15,7 +15,7 @@

Dashboard

- {% if current_user.has_permissions('manage_templates') and not current_service.templates %} + {% if current_user.has_permissions('manage_templates') and not current_service.all_templates %} {% include 'views/dashboard/write-first-messages.html' %} {% endif %} diff --git a/app/templates/views/templates/copy.html b/app/templates/views/templates/copy.html index 94d765f05..404e93db4 100644 --- a/app/templates/views/templates/copy.html +++ b/app/templates/views/templates/copy.html @@ -13,7 +13,7 @@