feat(api): fetch doc path for view metadata

ref: #463 #469
This commit is contained in:
2025-01-12 16:45:01 +09:30
parent ba2d809566
commit 6007668338
2 changed files with 39 additions and 21 deletions

View File

@ -71,6 +71,14 @@ class ReactUIMetadata(OverRideJSONAPIMetadata):
metadata["description"] = view.get_view_description()
if hasattr(view, 'get_model_documentation'):
if view.get_model_documentation():
metadata['documentation'] = str(settings.DOCS_ROOT) + str(view.get_model_documentation())
metadata['urls']: dict = {}
url_self = None
@ -123,24 +131,12 @@ class ReactUIMetadata(OverRideJSONAPIMetadata):
metadata['layout'] = view.get_page_layout()
if hasattr(view, 'get_model_documentation'):
if view.get_model_documentation():
metadata['documentation'] = view.get_model_documentation()
elif view.suffix == 'List':
if hasattr(view, 'table_fields'):
metadata['table_fields'] = view.get_table_fields()
if view.documentation:
metadata['documentation'] = view.documentation
if hasattr(view, 'page_layout'):
metadata['layout'] = view.get_page_layout()

View File

@ -328,9 +328,12 @@ class CommonViewSet(
is always gathered.
"""
_model_documentation: str = None
"""Cached Model Documentation URL"""
model_documentation: str = None
"""Model Documentation URL
"""User Defined Model Documentation URL
_Optional_, if specified will be add to detail view metadata"""
page_layout: list = []
@ -377,19 +380,38 @@ class CommonViewSet(
return None
def get_model_documentation(self):
def get_model_documentation(self) -> str:
"""Generate Documentation Path
if not self.model_documentation:
Documentation paths can be added in the following locations in priority of order (lower number is higher priority):
if hasattr(self.model, 'documentataion'):
1. `<viewset>.documentation`
self.model_documentation = self.model.documentation
2. `<model>.documentation`
else:
3. Auto-magic generate using app label and model name
self.model_documentation = ''
Returns:
str: Path to documentation
"""
if not self._model_documentation:
if getattr(self, 'documentation', None):
self._model_documentation = self.documentation
elif getattr(self.model, 'documentation', None):
self._model_documentation = self.model.documentation
elif getattr(self.model, '_meta', None):
self._model_documentation = self.model._meta.app_label + '/' + self.model._meta.model_name
return self._model_documentation
return self.model_documentation
def get_page_layout(self):