mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
inject origional context as obj_context
This commit is contained in:
parent
2522b88fc6
commit
457354c244
@ -18,15 +18,20 @@ class PluginTemplateContent:
|
|||||||
"""
|
"""
|
||||||
model = None
|
model = None
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj, context):
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
|
self.context = context
|
||||||
|
|
||||||
def render(self, template, extra_context=None):
|
def render(self, template, extra_context=None):
|
||||||
"""
|
"""
|
||||||
Convenience menthod for rendering the provided template name. The detail page object is automatically
|
Convenience menthod for rendering the provided template name. The detail page object is automatically
|
||||||
passed into the template context as `obj` but an additional context dictionary may be passed as `extra_context`.
|
passed into the template context as `obj` and the origional detail page's context is available as
|
||||||
|
`obj_context`. An additional context dictionary may be passed as `extra_context`.
|
||||||
"""
|
"""
|
||||||
context = {'obj': self.obj}
|
context = {
|
||||||
|
'obj': self.obj,
|
||||||
|
'obj_context': self.context
|
||||||
|
}
|
||||||
if isinstance(extra_context, dict):
|
if isinstance(extra_context, dict):
|
||||||
context.update(extra_context)
|
context.update(extra_context)
|
||||||
|
|
||||||
|
@ -8,16 +8,16 @@ from extras.plugins import get_content_classes
|
|||||||
register = template_.Library()
|
register = template_.Library()
|
||||||
|
|
||||||
|
|
||||||
def _get_registered_content(obj, method):
|
def _get_registered_content(obj, method, context):
|
||||||
"""
|
"""
|
||||||
Given an object and a PluginTemplateContent method name, return all the registered content for the
|
Given an object and a PluginTemplateContent method name and the template context, return all the
|
||||||
object's model.
|
registered content for the object's model.
|
||||||
"""
|
"""
|
||||||
html = ''
|
html = ''
|
||||||
|
|
||||||
plugin_template_classes = get_content_classes(obj._meta.label_lower)
|
plugin_template_classes = get_content_classes(obj._meta.label_lower)
|
||||||
for plugin_template_class in plugin_template_classes:
|
for plugin_template_class in plugin_template_classes:
|
||||||
plugin_template_renderer = plugin_template_class(obj)
|
plugin_template_renderer = plugin_template_class(obj, context)
|
||||||
try:
|
try:
|
||||||
content = getattr(plugin_template_renderer, method)()
|
content = getattr(plugin_template_renderer, method)()
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
@ -28,33 +28,33 @@ def _get_registered_content(obj, method):
|
|||||||
return mark_safe(html)
|
return mark_safe(html)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag(takes_context=True)
|
||||||
def plugin_buttons(obj):
|
def plugin_buttons(context, obj):
|
||||||
"""
|
"""
|
||||||
Fire signal to collect all buttons registered by plugins
|
Fire signal to collect all buttons registered by plugins
|
||||||
"""
|
"""
|
||||||
return _get_registered_content(obj, 'buttons')
|
return _get_registered_content(obj, 'buttons', context)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag(takes_context=True)
|
||||||
def plugin_left_page(obj):
|
def plugin_left_page(context, obj):
|
||||||
"""
|
"""
|
||||||
Fire signal to collect all left page content registered by plugins
|
Fire signal to collect all left page content registered by plugins
|
||||||
"""
|
"""
|
||||||
return _get_registered_content(obj, 'left_page')
|
return _get_registered_content(obj, 'left_page', context)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag(takes_context=True)
|
||||||
def plugin_right_page(obj):
|
def plugin_right_page(context, obj):
|
||||||
"""
|
"""
|
||||||
Fire signal to collect all right page content registered by plugins
|
Fire signal to collect all right page content registered by plugins
|
||||||
"""
|
"""
|
||||||
return _get_registered_content(obj, 'right_page')
|
return _get_registered_content(obj, 'right_page', context)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag(takes_context=True)
|
||||||
def plugin_full_width_page(obj):
|
def plugin_full_width_page(context, obj):
|
||||||
"""
|
"""
|
||||||
Fire signal to collect all full width page content registered by plugins
|
Fire signal to collect all full width page content registered by plugins
|
||||||
"""
|
"""
|
||||||
return _get_registered_content(obj, 'full_width_page')
|
return _get_registered_content(obj, 'full_width_page', context)
|
||||||
|
Loading…
Reference in New Issue
Block a user