mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Make creating TemplateListServices consistent
TemplateListServices are used when we want to show the service as an additional layer of hierarchy when a user copies a template, potentially across services [^1]. Normally a TemplateFolder is given "folders" and "templates" by TemplateList [^2]; TemplateListService was doing it the other way round and getting its own instead. Using a subclass of TemplateList means we can make the approach consistent, which will support the caching approach later on, as well as simplifying how we work with templates and folders. [^1]:2e637f801f/app/main/views/templates.py (L356)[^2]:bef0382cca/app/models/template_list.py (L31-L36)
This commit is contained in:
@@ -66,6 +66,28 @@ class TemplateList():
|
|||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceTemplateList(TemplateList):
|
||||||
|
def __iter__(self):
|
||||||
|
template_list_service = TemplateListService(
|
||||||
|
self.service,
|
||||||
|
templates=self.service.get_templates(
|
||||||
|
template_folder_id=None,
|
||||||
|
),
|
||||||
|
folders=self.service.get_template_folders(
|
||||||
|
parent_folder_id=None,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
yield template_list_service
|
||||||
|
|
||||||
|
yield from self.get_templates_and_folders(
|
||||||
|
self.template_type,
|
||||||
|
self.template_folder_id,
|
||||||
|
self.user,
|
||||||
|
ancestors=[template_list_service]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TemplateLists():
|
class TemplateLists():
|
||||||
|
|
||||||
def __init__(self, user):
|
def __init__(self, user):
|
||||||
@@ -84,20 +106,10 @@ class TemplateLists():
|
|||||||
return
|
return
|
||||||
|
|
||||||
for service in self.services:
|
for service in self.services:
|
||||||
|
yield from ServiceTemplateList(
|
||||||
template_list_service = TemplateListService(service)
|
service=service,
|
||||||
|
|
||||||
yield template_list_service
|
|
||||||
|
|
||||||
for service_templates_and_folders in TemplateList(
|
|
||||||
service, user=self.user
|
|
||||||
).get_templates_and_folders(
|
|
||||||
template_type='all',
|
|
||||||
template_folder_id=None,
|
|
||||||
user=self.user,
|
user=self.user,
|
||||||
ancestors=[template_list_service],
|
)
|
||||||
):
|
|
||||||
yield service_templates_and_folders
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def templates_to_show(self):
|
def templates_to_show(self):
|
||||||
@@ -183,21 +195,18 @@ class TemplateListFolder(TemplateListItem):
|
|||||||
|
|
||||||
|
|
||||||
class TemplateListService(TemplateListFolder):
|
class TemplateListService(TemplateListFolder):
|
||||||
|
|
||||||
is_service = True
|
is_service = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
service,
|
service,
|
||||||
|
templates,
|
||||||
|
folders,
|
||||||
):
|
):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
folder=service._dict,
|
folder=service._dict,
|
||||||
templates=service.get_templates(
|
templates=templates,
|
||||||
template_folder_id=None,
|
folders=folders,
|
||||||
),
|
|
||||||
folders=service.get_template_folders(
|
|
||||||
parent_folder_id=None,
|
|
||||||
),
|
|
||||||
ancestors=[],
|
ancestors=[],
|
||||||
service_id=service.id,
|
service_id=service.id,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user