mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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
|
||||
|
||||
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.registry import registry
|
||||
from plugin.urls import PLUGIN_BASE
|
||||
@ -578,10 +579,16 @@ class PanelMixin:
|
||||
if content_template:
|
||||
# Render content template to HTML
|
||||
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:
|
||||
# Render javascript template to HTML
|
||||
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
|
||||
required_keys = ['title', 'content']
|
||||
|
@ -245,4 +245,15 @@ def render_template(plugin, template_file, context=None):
|
||||
html = tmp.render(context)
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user