From 28ec3863849441bb632a9a8ab0df2de509e79155 Mon Sep 17 00:00:00 2001 From: Erik Stein Date: Tue, 24 Apr 2018 12:59:09 +0200 Subject: [PATCH] Optional context kwarg in get_context_data signature. --- content_plugins/base.py | 9 ++++----- content_plugins/plugins/mixins.py | 6 +++--- content_plugins/renderer.py | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/content_plugins/base.py b/content_plugins/base.py index 051f57c..862c130 100644 --- a/content_plugins/base.py +++ b/content_plugins/base.py @@ -69,9 +69,8 @@ class BasePlugin(models.Model): """ return self.get_template_names() - def get_context_data(self, **kwargs): - # context = kwargs.get('context', {}) - context = {} + def get_context_data(self, context=None, **kwargs): + context = context or {} context['content'] = self context['parent'] = self.parent if 'request_context' in kwargs: @@ -166,8 +165,8 @@ class SectionBase(StyleMixin, BasePlugin):

{{ subheading }}

""") - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) + def get_context_data(self, context=None, **kwargs): + context = super().get_context_data(context=context, **kwargs) context['slug'] = self.slug context['subheading'] = self.subheading return context diff --git a/content_plugins/plugins/mixins.py b/content_plugins/plugins/mixins.py index 8d4eca3..ee845e2 100644 --- a/content_plugins/plugins/mixins.py +++ b/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'): - context = super().get_context_data(**kwargs) + context = super().get_context_data(context=context, **kwargs) else: - context = {} + context = context or {} context['style'] = self.get_style_slug() return context diff --git a/content_plugins/renderer.py b/content_plugins/renderer.py index da78cdf..c002672 100644 --- a/content_plugins/renderer.py +++ b/content_plugins/renderer.py @@ -30,7 +30,7 @@ class ContentPluginRenderer(TemplatePluginRenderer): return super().regions(item, inherit_from=inherit_from, regions=regions) -# Preliminary class +# Experimental implementation class PluginRenderer(content_editor.PluginRenderer): def register(self, plugin, renderer=None): if not renderer: