diff --git a/src/backend/InvenTree/plugin/samples/integration/templates/uidemo/custom_part_panel.html b/src/backend/InvenTree/plugin/samples/integration/templates/uidemo/custom_part_panel.html new file mode 100644 index 0000000000..72815ed67e --- /dev/null +++ b/src/backend/InvenTree/plugin/samples/integration/templates/uidemo/custom_part_panel.html @@ -0,0 +1,30 @@ +{% load i18n %} + +

Custom Plugin Panel

+ +

+This content has been rendered by a custom plugin, and will be displayed for any "part" instance +(as long as the plugin is enabled). +This content has been rendered on the server, using the django templating system. +

+ +
Part Details
+ + + + + + + + + + + + + + + + + + +
Part Name{{ part.name }}
Part Description{{ part.description }}
Part Category{{ part.category.pathstring }}
Part IPN{% if part.IPN %}{{ part.IPN }}{% else %}No IPN specified{% endif %}
diff --git a/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py b/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py index 90cadb4265..856a73a474 100644 --- a/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py +++ b/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py @@ -2,7 +2,9 @@ from django.utils.translation import gettext_lazy as _ +from part.models import Part from plugin import InvenTreePlugin +from plugin.helpers import render_template, render_text from plugin.mixins import SettingsMixin, UserInterfaceMixin @@ -36,19 +38,47 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug # First, add a custom panel which will appear on every type of page # This panel will contain a simple message + + content = render_text( + """ + This is a sample panel which appears on every page. + It renders a simple string of HTML content. + +
+
Instance Details:
+ + """, + context={'instance_type': instance_type, 'instance_id': instance_id}, + ) + panels.append({ 'name': 'sample_panel', 'label': 'Sample Panel', - 'content': 'This is a sample panel which appears on every page. It renders a simple string of HTML content.', + 'content': content, }) # Next, add a custom panel which will appear on the 'part' page + # Note that this content is rendered from a template file, + # using the django templating system if self.get_setting('ENABLE_PART_PANELS') and instance_type == 'part': - panels.append({ - 'name': 'part_panel', - 'label': 'Part Panel', - 'content': 'This is a custom panel which appears on the Part view page.', - }) + try: + part = Part.objects.get(pk=instance_id) + except (Part.DoesNotExist, ValueError): + part = None + + if part: + content = render_template( + self, 'uidemo/custom_part_panel.html', context={'part': part} + ) + + panels.append({ + 'name': 'part_panel', + 'label': 'Part Panel', + 'content': content, + }) # Next, add a custom panel which will appear on the 'purchaseorder' page if (