Expand custom panel rendering demo

This commit is contained in:
Oliver Walters 2024-08-12 02:53:56 +00:00
parent 452d44cea3
commit 61eeb697f3
2 changed files with 66 additions and 6 deletions
src/backend/InvenTree/plugin/samples/integration

View File

@ -0,0 +1,30 @@
{% load i18n %}
<h4>Custom Plugin Panel</h4>
<p>
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.
</p>
<h5>Part Details</h5>
<table class='table table-striped table-condensed'>
<tr>
<th>Part Name</th>
<td>{{ part.name }}</td>
</tr>
<tr>
<th>Part Description</th>
<td>{{ part.description }}</td>
</tr>
<tr>
<th>Part Category</th>
<td>{{ part.category.pathstring }}</td>
</tr>
<tr>
<th>Part IPN</th>
<td>{% if part.IPN %}{{ part.IPN }}{% else %}<i>No IPN specified</i>{% endif %}</td>
</tr>
</table>

View File

@ -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 <i>sample panel</i> which appears on every page.
It renders a simple string of <b>HTML</b> content.
<br>
<h5>Instance Details:</h5>
<ul>
<li>Instance Type: {{ instance_type }}</li>
<li>Instance ID: {{ instance_id }}</li>
</ul>
""",
context={'instance_type': instance_type, 'instance_id': instance_id},
)
panels.append({
'name': 'sample_panel',
'label': 'Sample Panel',
'content': 'This is a <i>sample panel</i> which appears on every page. It renders a simple string of <b>HTML</b> 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 <b>Part</b> 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 (