mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Improvements for panel mixin sample
This commit is contained in:
parent
0797e9ebf0
commit
12c58b14d6
@ -75,7 +75,6 @@ class InvenTreePluginMixin:
|
|||||||
panels = []
|
panels = []
|
||||||
|
|
||||||
for plug in registry.with_mixin('panel'):
|
for plug in registry.with_mixin('panel'):
|
||||||
|
|
||||||
panels += plug.render_panels(self, self.request)
|
panels += plug.render_panels(self, self.request)
|
||||||
|
|
||||||
return panels
|
return panels
|
||||||
|
@ -606,18 +606,18 @@ class PanelMixin:
|
|||||||
for panel in self.get_custom_panels(view, request):
|
for panel in self.get_custom_panels(view, request):
|
||||||
|
|
||||||
if 'content_template' in panel:
|
if 'content_template' in panel:
|
||||||
# TODO: Render the actual content
|
# TODO: Render the actual HTML content from a template file
|
||||||
...
|
...
|
||||||
|
|
||||||
if 'javascript_template' in panel:
|
if 'javascript_template' in panel:
|
||||||
# TODO: Render the actual content
|
# TODO: Render the actual javascript content from a template file
|
||||||
...
|
...
|
||||||
|
|
||||||
# Check for required keys
|
# Check for required keys
|
||||||
required_keys = ['title', 'content']
|
required_keys = ['title', 'content']
|
||||||
|
|
||||||
if any([key not in panel for key in required_keys]):
|
if any([key not in panel for key in required_keys]):
|
||||||
logger.warning(f"Custom panel for plugin '{__class__}' is missing a required key")
|
logger.warning(f"Custom panel for plugin {__class__} is missing a required parameter")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Add some information on this plugin
|
# Add some information on this plugin
|
||||||
|
@ -18,6 +18,19 @@ class CustomPanelSample(PanelMixin, IntegrationPluginBase):
|
|||||||
PLUGIN_SLUG = "panel"
|
PLUGIN_SLUG = "panel"
|
||||||
PLUGIN_TITLE = "Custom Panel Example"
|
PLUGIN_TITLE = "Custom Panel Example"
|
||||||
|
|
||||||
|
def render_location_info(self, loc):
|
||||||
|
"""
|
||||||
|
Demonstrate that we can render information particular to a page
|
||||||
|
"""
|
||||||
|
return f"""
|
||||||
|
<h5>Location Information</h5>
|
||||||
|
<em>This location has no sublocations!</em>
|
||||||
|
<ul>
|
||||||
|
<li><b>Name</b>: {loc.name}</li>
|
||||||
|
<li><b>Path</b>: {loc.pathstring}</li>
|
||||||
|
</ul>
|
||||||
|
"""
|
||||||
|
|
||||||
def get_custom_panels(self, view, request):
|
def get_custom_panels(self, view, request):
|
||||||
|
|
||||||
panels = [
|
panels = [
|
||||||
@ -46,14 +59,15 @@ class CustomPanelSample(PanelMixin, IntegrationPluginBase):
|
|||||||
# This panel will *only* display on the StockLocation view,
|
# This panel will *only* display on the StockLocation view,
|
||||||
# and *only* if the StockLocation has *no* child locations
|
# and *only* if the StockLocation has *no* child locations
|
||||||
if isinstance(view, StockLocationDetail):
|
if isinstance(view, StockLocationDetail):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loc = view.get_object()
|
loc = view.get_object()
|
||||||
|
|
||||||
if not loc.get_descendants(include_self=False).exists():
|
if not loc.get_descendants(include_self=False).exists():
|
||||||
panels.append({
|
panels.append({
|
||||||
'title': 'Childless',
|
'title': 'Childless Location',
|
||||||
'icon': 'fa-user',
|
'icon': 'fa-user',
|
||||||
'content': '<h4>I have no children!</h4>'
|
'content': self.render_location_info(loc),
|
||||||
})
|
})
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user