Initial commit
This commit is contained in:
commit
da33884cd2
|
@ -0,0 +1 @@
|
|||
|
|
@ -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)
|
|
@ -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>
|
||||
|
||||
|
|
@ -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')
|
||||
)
|
|
@ -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)
|
Reference in New Issue