Browse Source

Optional context kwarg in get_context_data signature.

master
Erik Stein 7 years ago
parent
commit
28ec386384
  1. 9
      content_plugins/base.py
  2. 6
      content_plugins/plugins/mixins.py
  3. 2
      content_plugins/renderer.py

9
content_plugins/base.py

@ -69,9 +69,8 @@ class BasePlugin(models.Model):
""" """
return self.get_template_names() return self.get_template_names()
def get_context_data(self, **kwargs): def get_context_data(self, context=None, **kwargs):
# context = kwargs.get('context', {}) context = context or {}
context = {}
context['content'] = self context['content'] = self
context['parent'] = self.parent context['parent'] = self.parent
if 'request_context' in kwargs: if 'request_context' in kwargs:
@ -166,8 +165,8 @@ class SectionBase(StyleMixin, BasePlugin):
<h2>{{ subheading }}</h2> <h2>{{ subheading }}</h2>
""") """)
def get_context_data(self, **kwargs): def get_context_data(self, context=None, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(context=context, **kwargs)
context['slug'] = self.slug context['slug'] = self.slug
context['subheading'] = self.subheading context['subheading'] = self.subheading
return context return context

6
content_plugins/plugins/mixins.py

@ -45,10 +45,10 @@ class StyleMixin(models.Model):
) )
] ]
def get_context_data(self, **kwargs): def get_context_data(self, context=None, **kwargs):
if hasattr(super(), 'get_context_data'): if hasattr(super(), 'get_context_data'):
context = super().get_context_data(**kwargs) context = super().get_context_data(context=context, **kwargs)
else: else:
context = {} context = context or {}
context['style'] = self.get_style_slug() context['style'] = self.get_style_slug()
return context return context

2
content_plugins/renderer.py

@ -30,7 +30,7 @@ class ContentPluginRenderer(TemplatePluginRenderer):
return super().regions(item, inherit_from=inherit_from, regions=regions) return super().regions(item, inherit_from=inherit_from, regions=regions)
# Preliminary class # Experimental implementation
class PluginRenderer(content_editor.PluginRenderer): class PluginRenderer(content_editor.PluginRenderer):
def register(self, plugin, renderer=None): def register(self, plugin, renderer=None):
if not renderer: if not renderer:

Loading…
Cancel
Save