refactor(api): Adjust viewset common so that page_layout is available for base

ref: #248 #348
This commit is contained in:
2024-10-15 20:15:53 +09:30
parent 94f3925127
commit 62ca58e820

View File

@ -50,6 +50,18 @@ class CommonViewSet(
required to generate the UI.
"""
model_documentation: str = None
"""Model Documentation URL
_Optional_, if specified will be add to detail view metadata"""
page_layout: list = []
""" Page layout class
_Optional_, used by metadata to add the page layout to the HTTP/Options method
for detail view, Enables the UI can setup the page layout.
"""
permission_classes = [ OrganizationPermissionAPI ]
"""Permission Class
@ -61,6 +73,38 @@ class CommonViewSet(
view_name: str = None
def get_model_documentation(self):
if not self.model_documentation:
if hasattr(self.model, 'documentataion'):
self.model_documentation = self.model.documentation
else:
self.model_documentation = ''
return self.model_documentation
def get_page_layout(self):
if len(self.page_layout) < 1:
if hasattr(self, 'model'):
if hasattr(self.model, 'page_layout'):
self.page_layout = self.model.page_layout
else:
self.page_layout = []
return self.page_layout
def get_view_description(self, html=False) -> str:
if not self.view_description:
@ -111,18 +155,6 @@ class ModelViewSetBase(
_Mandatory_, Django model used for this view.
"""
model_documentation: str = None
"""Model Documentation URL
_Optional_, if specified will be add to detail view metadata"""
page_layout: list = []
""" Page layout class
_Optional_, used by metadata to add the page layout to the HTTP/Options method
for detail view, Enables the UI can setup the page layout.
"""
queryset: object = None
"""View Queryset
@ -136,36 +168,6 @@ class ModelViewSetBase(
"""
def get_model_documentation(self):
if not self.model_documentation:
if hasattr(self.model, 'documentataion'):
self.model_documentation = self.model.documentation
else:
self.model_documentation = ''
return self.model_documentation
def get_page_layout(self):
if len(self.page_layout) < 1:
if hasattr(self.model, 'page_layout'):
self.page_layout = self.model.page_layout
else:
self.page_layout = []
return self.page_layout
def get_queryset(self):
if not self.queryset: