|
|
@@ -1,4 +1,5 @@
|
|
|
from django import template as template_
|
|
|
+from django.conf import settings
|
|
|
from django.utils.safestring import mark_safe
|
|
|
|
|
|
from extras.registry import registry
|
|
|
@@ -6,18 +7,30 @@ from extras.registry import registry
|
|
|
register = template_.Library()
|
|
|
|
|
|
|
|
|
-def _get_registered_content(obj, method, context):
|
|
|
+def _get_registered_content(obj, method, template_context):
|
|
|
"""
|
|
|
Given an object and a PluginTemplateExtension method name and the template context, return all the
|
|
|
registered content for the object's model.
|
|
|
"""
|
|
|
html = ''
|
|
|
+ context = {
|
|
|
+ 'obj': obj,
|
|
|
+ 'request': template_context['request'],
|
|
|
+ 'settings': template_context['settings'],
|
|
|
+ 'config': {}, # Defined per-plugin
|
|
|
+ }
|
|
|
|
|
|
model_name = obj._meta.label_lower
|
|
|
- for template_extension_class in registry['plugin_template_extensions'].get(model_name, []):
|
|
|
- template_extension_instance = template_extension_class(obj, context)
|
|
|
+ template_extensions = registry['plugin_template_extensions'].get(model_name, [])
|
|
|
+ for template_extension in template_extensions:
|
|
|
+
|
|
|
+ # Update context with plugin-specific configuration parameters
|
|
|
+ plugin_name = template_extension.__module__.split('.')[0]
|
|
|
+ context['config'] = settings.PLUGINS_CONFIG.get(plugin_name)
|
|
|
+
|
|
|
+ instance = template_extension(context)
|
|
|
try:
|
|
|
- content = getattr(template_extension_instance, method)()
|
|
|
+ content = getattr(instance, method)()
|
|
|
except NotImplementedError:
|
|
|
# This content renderer class does not define content for this method
|
|
|
continue
|