mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Custom panel content gets passed through the templating engine
This commit is contained in:
parent
7d9690b974
commit
14b60cdedc
@ -11,7 +11,8 @@ from django.db.utils import OperationalError, ProgrammingError
|
|||||||
|
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
|
|
||||||
from plugin.helpers import MixinImplementationError, MixinNotImplementedError, render_template
|
from plugin.helpers import MixinImplementationError, MixinNotImplementedError
|
||||||
|
from plugin.helpers import render_template, render_text
|
||||||
from plugin.models import PluginConfig, PluginSetting
|
from plugin.models import PluginConfig, PluginSetting
|
||||||
from plugin.registry import registry
|
from plugin.registry import registry
|
||||||
from plugin.urls import PLUGIN_BASE
|
from plugin.urls import PLUGIN_BASE
|
||||||
@ -578,10 +579,16 @@ class PanelMixin:
|
|||||||
if content_template:
|
if content_template:
|
||||||
# Render content template to HTML
|
# Render content template to HTML
|
||||||
panel['content'] = render_template(self, content_template, ctx)
|
panel['content'] = render_template(self, content_template, ctx)
|
||||||
|
else:
|
||||||
|
# Render content string to HTML
|
||||||
|
panel['content'] = render_text(panel.get('content', ''), ctx)
|
||||||
|
|
||||||
if javascript_template:
|
if javascript_template:
|
||||||
# Render javascript template to HTML
|
# Render javascript template to HTML
|
||||||
panel['javascript'] = render_template(self, javascript_template, ctx)
|
panel['javascript'] = render_template(self, javascript_template, ctx)
|
||||||
|
else:
|
||||||
|
# Render javascript string to HTML
|
||||||
|
panel['javascript'] = render_text(panel.get('javascript', ''), ctx)
|
||||||
|
|
||||||
# Check for required keys
|
# Check for required keys
|
||||||
required_keys = ['title', 'content']
|
required_keys = ['title', 'content']
|
||||||
|
@ -245,4 +245,15 @@ def render_template(plugin, template_file, context=None):
|
|||||||
html = tmp.render(context)
|
html = tmp.render(context)
|
||||||
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
|
def render_text(text, context=None):
|
||||||
|
"""
|
||||||
|
Locate a raw string with provided context
|
||||||
|
"""
|
||||||
|
|
||||||
|
ctx = template.Context(context)
|
||||||
|
|
||||||
|
return template.Template(text).render(ctx)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
Loading…
x
Reference in New Issue
Block a user