""" Sample plugin which renders custom panels on certain pages """ from part.views import PartDetail from plugin import InvenTreePlugin from plugin.mixins import PanelMixin, SettingsMixin from stock.views import StockLocationDetail class CustomPanelSample(PanelMixin, SettingsMixin, InvenTreePlugin): """ A sample plugin which renders some custom panels. """ NAME = "CustomPanelExample" SLUG = "samplepanel" TITLE = "Custom Panel Example" DESCRIPTION = "An example plugin demonstrating how custom panels can be added to the user interface" VERSION = "0.1" SETTINGS = { 'ENABLE_HELLO_WORLD': { 'name': 'Enable Hello World', 'description': 'Enable a custom hello world panel on every page', 'default': False, 'validator': bool, }, 'ENABLE_BROKEN_PANEL': { 'name': 'Enable Broken Panel', 'description': 'Enable a panel with rendering issues', 'default': False, 'validator': bool, } } def get_panel_context(self, view, request, context): ctx = super().get_panel_context(view, request, context) # If we are looking at a StockLocationDetail view, add location context object if isinstance(view, StockLocationDetail): ctx['location'] = view.get_object() return ctx def get_custom_panels(self, view, request): """ You can decide at run-time which custom panels you want to display! - Display on every page - Only on a single page or set of pages - Only for a specific instance (e.g. part) - Based on the user viewing the page! """ panels = [ { # Simple panel without any actual content 'title': 'No Content', } ] if self.get_setting('ENABLE_HELLO_WORLD'): # We can use template rendering in the raw content content = """ Hello world!
Path | {{ request.path }} |
User | {{ user.username }} |