2013-12-11 14:29:52 +01:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from django.template import loader
|
|
|
|
|
2014-04-03 11:24:58 +02:00
|
|
|
from djangocms_text_ckeditor.cms_plugins import TextPlugin
|
2013-12-11 14:29:52 +01:00
|
|
|
from cms.plugin_pool import plugin_pool
|
|
|
|
|
|
|
|
class AjaxTextPlugin(TextPlugin):
|
|
|
|
name = _(u'Text (asynchronous loading)')
|
2014-02-10 08:37:17 +01:00
|
|
|
ajax_render_template = 'cms_ajax_text_plugin/plugin.html'
|
2014-06-11 16:11:40 +02:00
|
|
|
text_enabled = True
|
2013-12-11 14:29:52 +01:00
|
|
|
|
|
|
|
def get_ajax_body(self, instance, context):
|
|
|
|
t = loader.get_template(self.ajax_render_template)
|
|
|
|
return t.render(context)
|
|
|
|
|
|
|
|
def render(self, context, instance, placeholder):
|
|
|
|
request = context.get('request')
|
2014-05-26 20:41:43 +02:00
|
|
|
context['instance'] = instance
|
2014-02-05 15:49:06 +01:00
|
|
|
if 'updatecache' in request.GET:
|
|
|
|
instance.args = '?updatecache'
|
2013-12-11 14:29:52 +01:00
|
|
|
edit_mode = request and 'edit' in request.GET
|
|
|
|
is_ajax = request and request.is_ajax()
|
|
|
|
if edit_mode or is_ajax:
|
2013-12-31 11:20:56 +01:00
|
|
|
context = super(AjaxTextPlugin, self).render(context, instance, placeholder)
|
2013-12-11 14:29:52 +01:00
|
|
|
return context
|
|
|
|
|
|
|
|
context['body'] = self.get_ajax_body(instance, context)
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugin_pool.register_plugin(AjaxTextPlugin)
|