1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Restrict context data available to PluginTemplateExtensions

This commit is contained in:
Jeremy Stretch
2020-03-26 16:50:55 -04:00
parent e7f7b14214
commit f03cc96050
3 changed files with 32 additions and 18 deletions

View File

@@ -83,8 +83,7 @@ class PluginTemplateExtension:
"""
model = None
def __init__(self, obj, context):
self.obj = obj
def __init__(self, context):
self.context = context
def render(self, template, extra_context=None):
@@ -93,14 +92,12 @@ class PluginTemplateExtension:
passed into the template context as `obj` and the original detail page's context is available as
`obj_context`. An additional context dictionary may be passed as `extra_context`.
"""
context = {
'obj': self.obj,
'obj_context': self.context
}
if isinstance(extra_context, dict):
context.update(extra_context)
if extra_context is None:
extra_context = {}
elif not isinstance(extra_context, dict):
raise TypeError("extra_context must be a dictionary")
return get_template(template).render(context)
return get_template(template).render({**self.context, **extra_context})
def left_page(self):
"""