1414from djangocms_rest .utils import get_object , get_placeholder
1515from djangocms_rest .views_base import BaseAPIView
1616
17- try :
18- from drf_spectacular .utils import extend_schema
19- except ImportError :
20-
21- def extend_schema (* args , ** kwargs ):
22- """
23- Empty decorator for when drf-spectacular is not installed.
24- """
25-
26- def decorator (func ):
27- return func
28-
29- return decorator
30-
3117
3218class LanguageListView (BaseAPIView ):
33- """
34- List of languages available for the site. For each language the API returns the
35- link to the list of pages for that languages.
36- """
37-
38- @extend_schema (
39- responses = {200 : LanguageSerializer },
40- )
19+ serializer_class = LanguageSerializer
20+
4121 def get (self , request : Request ) -> Response :
22+ """List of languages available for the site. For each language the API returns the
23+ link to the list of pages for that languages."""
4224 languages = get_languages ().get (get_current_site (request ).id , None )
4325 if languages is None :
4426 raise Http404
@@ -49,16 +31,11 @@ def get(self, request: Request) -> Response:
4931
5032
5133class PageTreeListView (BaseAPIView ):
52- """
53- List of all pages on this site for a given language.
54- """
55-
5634 permission_classes = [IsAllowedLanguage ]
35+ serializer_class = PageMetaSerializer
5736
58- @extend_schema (
59- responses = PageMetaSerializer , description = "Get a list of all pages for the given language on the current site."
60- )
6137 def get (self , request , language ):
38+ """List of all pages on this site for a given language."""
6239 site = self .site
6340 qs = Page .objects .filter (node__site = site )
6441 if request .user .is_anonymous :
@@ -77,18 +54,12 @@ def get(self, request, language):
7754
7855
7956class PageDetailView (BaseAPIView ):
80- """
81- Retrieve a page instance. The page instance includes the placeholders and
82- their links to retrieve dynamic content.
83- """
84-
8557 permission_classes = [CanViewPage ]
58+ serializer_class = PageContentSerializer
8659
87- @extend_schema (
88- responses = PageContentSerializer ,
89- description = "Get a page instance with placeholders and their links to retrieve dynamic content." ,
90- )
9160 def get (self , request : Request , language : str , path : str = "" ) -> Response :
61+ """Retrieve a page instance. The page instance includes the placeholders and
62+ their links to retrieve dynamic content."""
9263 site = self .site
9364 page = get_object (site , path )
9465 self .check_object_permissions (request , page )
@@ -102,23 +73,22 @@ def get(self, request: Request, language: str, path: str = "") -> Response:
10273
10374
10475class PlaceholderDetailView (BaseAPIView ):
105- """Placeholder contain the dynamic content. This view retrieves the content as a
106- structured nested object.
107-
108- Attributes:
109-
110- - "slot": The slot name of the placeholder.
111- - "content": The content of the placeholder as a nested JSON tree
112- - "language": The language of the content
113- - "label": The verbose label of the placeholder
114-
115- Optional (if the get parameter `?html=1` is added to the API url):
116- - "html": The content rendered as html. Sekizai blocks such as "js" or "css" will be added
117- as separate attributes"""
118-
76+ serializer_class = PlaceholderSerializer
11977 permission_classes = [CanViewPageContent ]
12078
12179 def get (self , request : Request , language : str , content_type_id : int , object_id : int , slot : str ) -> Response :
80+ """Placeholder contain the dynamic content. This view retrieves the content as a
81+ structured nested object.
82+
83+ Attributes:
84+ - "slot": The slot name of the placeholder.
85+ - "content": The content of the placeholder as a nested JSON tree
86+ - "language": The language of the content
87+ - "label": The verbose label of the placeholder
88+
89+ Optional (if the get parameter `?html=1` is added to the API url):
90+ - "html": The content rendered as html. Sekizai blocks such as "js" or "css" will be added
91+ as separate attributes"""
12292 placeholder = get_placeholder (content_type_id , object_id , slot )
12393 if placeholder is None :
12494 raise Http404
@@ -129,5 +99,5 @@ def get(self, request: Request, language: str, content_type_id: int, object_id:
12999
130100 self .check_object_permissions (request , source )
131101
132- serializer = PlaceholderSerializer ( request , placeholder , language , read_only = True )
102+ serializer = self . serializer_class ( instance = placeholder , request = request , language = language , read_only = True )
133103 return Response (serializer .data )
0 commit comments