Add a template list API view
Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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<name>[-\w]+)/$', APITemplateView.as_view(),
|
||||
name='template-detail'
|
||||
|
||||
Reference in New Issue
Block a user