mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Expand custom panel rendering demo
This commit is contained in:
@ -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>
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from part.models import Part
|
||||||
from plugin import InvenTreePlugin
|
from plugin import InvenTreePlugin
|
||||||
|
from plugin.helpers import render_template, render_text
|
||||||
from plugin.mixins import SettingsMixin, UserInterfaceMixin
|
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
|
# First, add a custom panel which will appear on every type of page
|
||||||
# This panel will contain a simple message
|
# 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({
|
panels.append({
|
||||||
'name': 'sample_panel',
|
'name': 'sample_panel',
|
||||||
'label': '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
|
# 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':
|
if self.get_setting('ENABLE_PART_PANELS') and instance_type == 'part':
|
||||||
panels.append({
|
try:
|
||||||
'name': 'part_panel',
|
part = Part.objects.get(pk=instance_id)
|
||||||
'label': 'Part Panel',
|
except (Part.DoesNotExist, ValueError):
|
||||||
'content': 'This is a custom panel which appears on the <b>Part</b> view page.',
|
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
|
# Next, add a custom panel which will appear on the 'purchaseorder' page
|
||||||
if (
|
if (
|
||||||
|
Reference in New Issue
Block a user