forked from django-cms/django-cms
/
cms_plugins.py
36 lines (30 loc) · 1.34 KB
/
cms_plugins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from django.utils.safestring import mark_safe
from cms.plugin_pool import plugin_pool
from cms.plugin_base import CMSPluginBase
from django.utils.translation import ugettext_lazy as _
from cms.plugin_rendering import render_plugins
from stacks.fields import StackSearchField
from stacks.models import StackLink
from cms.plugins.utils import get_plugins
class StackPlugin(CMSPluginBase):
model = StackLink
name = _("Stack")
render_template = "cms/plugins/stacks.html"
admin_preview = False
def render(self, context, instance, placeholder):
# TODO: once we drop 2.3.x support we can just use the "render_plugin" templatetag
# instead of rendering html here.
plugins = get_plugins(context['request'], instance.stack.content)
processors = ()
html_content = mark_safe(u"".join(render_plugins(plugins, context, placeholder, processors)))
context.update({
'instance': instance,
'placeholder': placeholder,
'content': html_content,
})
return context
def formfield_for_dbfield(self, db_field, request=None, **kwargs):
if db_field.name == "stack":
return StackSearchField(**kwargs)
return super(StackPlugin, self).formfield_for_dbfield(db_field, request=request, **kwargs)
plugin_pool.register_plugin(StackPlugin)