In AJAX view return 404 on absent plugin (fixes #5092)
When the view fails, stop polling if status is 404, otherwise continue polling but use an exponential backoff between retries.
This commit is contained in:
parent
85bd25bf34
commit
bb7c7a0e8a
|
@ -9,21 +9,26 @@
|
|||
} else {
|
||||
var $container = $("#block-plugin-ajax-{{ plugin_id }}");
|
||||
var ajax_refresh = {{ ajax_refresh }};
|
||||
var exponential_refresh = ajax_refresh;
|
||||
var reload = function () {
|
||||
$container.removeClass('block-plugin-ajax-failed');
|
||||
$container.addClass('block-plugin-ajax-loading');
|
||||
$.getJSON('{% url 'ajax_render' plugin_id=plugin_id %}{{ plugin_args|safe }}', function (result) {
|
||||
$container.html(result.content);
|
||||
$container.removeClass('block-plugin-ajax-loading');
|
||||
})
|
||||
.fail(function () {
|
||||
$container.addClass('block-plugin-ajax-failed');
|
||||
})
|
||||
.always(function () {
|
||||
if (ajax_refresh > 0) {
|
||||
setTimeout(reload, ajax_refresh*1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
exponential_refresh = ajax_refresh;
|
||||
})
|
||||
.fail(function (jqXHR) {
|
||||
$container.addClass('block-plugin-ajax-failed');
|
||||
if (ajax_refresh > 0 && jqXHR.status != 404) {
|
||||
/* continue polling but use exponential backoff */
|
||||
exponential_refresh = exponential_refresh * 2;
|
||||
setTimeout(reload, exponential_refresh*1000);
|
||||
}
|
||||
})
|
||||
};
|
||||
$(document).ready(function(){
|
||||
reload();
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
import json
|
||||
import logging
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.template import RequestContext, loader
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from cms.models import CMSPlugin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def ajax_render(request, plugin_id):
|
||||
plugin = CMSPlugin.objects.get(pk=plugin_id)
|
||||
context = RequestContext(request)
|
||||
context['ajaxy'] = False
|
||||
plugin = get_object_or_404(CMSPlugin, pk=plugin_id)
|
||||
rendered = plugin.render_plugin(context)
|
||||
# use another template to render accumulated js and css declarations from sekizai
|
||||
content = loader.render_to_string('cmsplugin_blurp/sekizai_render.html',
|
||||
{'content': rendered},
|
||||
context)
|
||||
{'content': rendered}, context)
|
||||
return HttpResponse(json.dumps({'content': content}))
|
||||
|
||||
|
|
Reference in New Issue