diff --git a/mayan/apps/common/api_views.py b/mayan/apps/common/api_views.py index b29144c789..9c632282a2 100644 --- a/mayan/apps/common/api_views.py +++ b/mayan/apps/common/api_views.py @@ -17,6 +17,18 @@ class APIContentTypeList(generics.ListAPIView): queryset = ContentType.objects.order_by('app_label', 'model') +class APITemplateListView(generics.ListAPIView): + """ + Returns a list of partial templates. + get: Returns a list of partial templates. + """ + serializer_class = TemplateSerializer + permission_classes = (IsAuthenticated,) + + def get_queryset(self): + return Template.all(rendered=True, request=self.request) + + class APITemplateView(generics.RetrieveAPIView): """ Returns the selected partial template details. @@ -26,4 +38,6 @@ class APITemplateView(generics.RetrieveAPIView): permission_classes = (IsAuthenticated,) def get_object(self): - return Template.get(self.kwargs['name']).render(request=self.request) + return Template.get(name=self.kwargs['name']).render( + request=self.request + ) diff --git a/mayan/apps/common/classes.py b/mayan/apps/common/classes.py index 08f4102488..2c52f2e16a 100644 --- a/mayan/apps/common/classes.py +++ b/mayan/apps/common/classes.py @@ -271,6 +271,17 @@ class Package(object): class Template(object): _registry = {} + @classmethod + def all(cls, rendered=False, request=None): + if not rendered: + return cls._registry.values() + else: + result = [] + for template in cls._registry.values(): + result.append(template.render(request=request)) + return result + + @classmethod def get(cls, name): return cls._registry[name] diff --git a/mayan/apps/common/urls.py b/mayan/apps/common/urls.py index 58acf75900..b607b1a567 100644 --- a/mayan/apps/common/urls.py +++ b/mayan/apps/common/urls.py @@ -3,7 +3,9 @@ from __future__ import unicode_literals from django.conf.urls import url from django.views.i18n import javascript_catalog, set_language -from .api_views import APIContentTypeList, APITemplateView +from .api_views import ( + APIContentTypeList, APITemplateListView, APITemplateView +) from .views import ( AboutView, CheckVersionView, CurrentUserLocaleProfileDetailsView, CurrentUserLocaleProfileEditView, FaviconRedirectView, HomeView, @@ -68,6 +70,10 @@ api_urls = [ r'^content_types/$', APIContentTypeList.as_view(), name='content-type-list' ), + url( + r'^templates/$', APITemplateListView.as_view(), + name='template-list' + ), url( r'^templates/(?P[-\w]+)/$', APITemplateView.as_view(), name='template-detail'