summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei MIHAI <smihai@entrouvert.com>2013-12-11 13:29:52 (GMT)
committerSerghei MIHAI <smihai@entrouvert.com>2013-12-11 13:29:52 (GMT)
commitda33884cd28f7b2d1f1fcd0c04fb256e383522e3 (patch)
tree7eb49f2e4ab0187b987c71e0b60f899f9b285044
downloadcms-ajax-text-plugin-da33884cd28f7b2d1f1fcd0c04fb256e383522e3.zip
cms-ajax-text-plugin-da33884cd28f7b2d1f1fcd0c04fb256e383522e3.tar.gz
cms-ajax-text-plugin-da33884cd28f7b2d1f1fcd0c04fb256e383522e3.tar.bz2
Initial commit
-rw-r--r--__init__.py1
-rw-r--r--cms_plugins.py29
-rw-r--r--templates/plugin/ajax_text.html18
-rw-r--r--urls.py7
-rw-r--r--views.py11
5 files changed, 66 insertions, 0 deletions
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1 @@
+
diff --git a/cms_plugins.py b/cms_plugins.py
new file mode 100644
index 0000000..96eb85b
--- /dev/null
+++ b/cms_plugins.py
@@ -0,0 +1,29 @@
+from django.utils.translation import ugettext_lazy as _
+from django.template import loader
+
+from cmsplugin_text_wrapper.cms_plugins import TextPlugin
+from cms.plugin_pool import plugin_pool
+
+class AjaxTextPlugin(TextPlugin):
+ name = _(u'Text (asynchronous loading)')
+ ajax_render_template = 'plugin/ajax_text.html'
+
+ 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):
+ context = super(AjaxTextPlugin, self).render(context, instance, placeholder)
+ context['object'] = instance
+ request = context.get('request')
+ edit_mode = request and 'edit' in request.GET
+ is_ajax = request and request.is_ajax()
+ if edit_mode or is_ajax:
+ return context
+
+ context['body'] = self.get_ajax_body(instance, context)
+ return context
+
+
+
+plugin_pool.register_plugin(AjaxTextPlugin)
diff --git a/templates/plugin/ajax_text.html b/templates/plugin/ajax_text.html
new file mode 100644
index 0000000..4f98780
--- /dev/null
+++ b/templates/plugin/ajax_text.html
@@ -0,0 +1,18 @@
+{% load i18n %}
+{% load sekizai_tags %}
+
+{% addtoblock "js" %}<script type="text/javascript" src="{{ STATIC_URL }}admin/js/jquery.min.js"></script>{% endaddtoblock %}
+
+{% addtoblock "js" %}
+<script type="text/javascript">
+ $(document).ready(function(){
+ $("#plugin-{{ object.id }}").load('{% url 'ajax_render' object.id %}');
+ });
+</script>
+{% endaddtoblock %}
+
+<div id="plugin-{{ object.id }}" class="loading">
+ {% trans "loading..." %}
+</div>
+
+
diff --git a/urls.py b/urls.py
new file mode 100644
index 0000000..d3b568c
--- /dev/null
+++ b/urls.py
@@ -0,0 +1,7 @@
+from django.conf.urls import patterns, url
+from views import ajax_render
+
+urlpatterns = patterns('',
+ url(r'^async_text/(?P<plugin_id>\d+)/$', ajax_render,
+ name = 'ajax_render')
+ )
diff --git a/views.py b/views.py
new file mode 100644
index 0000000..b0e19b8
--- /dev/null
+++ b/views.py
@@ -0,0 +1,11 @@
+from django.http import HttpResponse
+from django.template import RequestContext
+
+
+from cms.models import CMSPlugin
+
+def ajax_render(request, plugin_id):
+ plugin = CMSPlugin.objects.get(pk=plugin_id)
+ context = RequestContext(request)
+ rendered = plugin.render_plugin(context)
+ return HttpResponse(rendered)