2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-05-23 09:35:30 +00:00

Improvements for panel mixin sample

This commit is contained in:
Oliver Walters
2022-05-06 23:19:47 +10:00
parent 0797e9ebf0
commit 12c58b14d6
3 changed files with 19 additions and 6 deletions
@@ -18,6 +18,19 @@ class CustomPanelSample(PanelMixin, IntegrationPluginBase):
PLUGIN_SLUG = "panel"
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):
panels = [
@@ -46,14 +59,15 @@ class CustomPanelSample(PanelMixin, IntegrationPluginBase):
# This panel will *only* display on the StockLocation view,
# and *only* if the StockLocation has *no* child locations
if isinstance(view, StockLocationDetail):
try:
loc = view.get_object()
if not loc.get_descendants(include_self=False).exists():
panels.append({
'title': 'Childless',
'title': 'Childless Location',
'icon': 'fa-user',
'content': '<h4>I have no children!</h4>'
'content': self.render_location_info(loc),
})
except:
pass