Remove deprecated js_template handling from modal workflow

pull/4817/head
Matt Westcott 2018-10-17 11:47:53 +01:00 zatwierdzone przez Matt Westcott
rodzic 771eb42d05
commit 65fb1e9cd4
2 zmienionych plików z 11 dodań i 52 usunięć

Wyświetl plik

@ -1,49 +1,22 @@
import json
import warnings
from django.http import HttpResponse, JsonResponse
from django.http import JsonResponse
from django.template.loader import render_to_string
from wagtail.utils.deprecation import RemovedInWagtail24Warning
def render_modal_workflow(request, html_template, js_template, template_vars=None, json_data=None):
def render_modal_workflow(request, html_template, js_template=None, template_vars=None, json_data=None):
""""
Render a response consisting of an HTML chunk and a JS onload chunk
in the format required by the modal-workflow framework.
"""
if js_template:
warnings.warn(
"Passing a JS template to render_modal_workflow is deprecated. "
"Use an 'onload' dict on the ModalWorkflow constructor instead",
category=RemovedInWagtail24Warning
)
# construct response as Javascript, including a JS function as the 'onload' field
response_keyvars = []
raise TypeError("Passing a js_template argument to render_modal_workflow is no longer supported")
if html_template:
html = render_to_string(html_template, template_vars or {}, request=request)
response_keyvars.append('"html": %s' % json.dumps(html))
# construct response as JSON
response = {}
js = render_to_string(js_template, template_vars or {}, request=request)
response_keyvars.append('"onload": %s' % js)
if html_template:
response['html'] = render_to_string(html_template, template_vars or {}, request=request)
if json_data:
for key, val in json_data.items():
response_keyvars.append("%s: %s" % (json.dumps(key), json.dumps(val)))
if json_data:
response.update(json_data)
response_text = "{%s}" % ','.join(response_keyvars)
return HttpResponse(response_text, content_type="text/javascript")
else:
# construct response as JSON
response = {}
if html_template:
response['html'] = render_to_string(html_template, template_vars or {}, request=request)
if json_data:
response.update(json_data)
return JsonResponse(response)
return JsonResponse(response)

Wyświetl plik

@ -55,15 +55,7 @@ function ModalWorkflow(opts) {
};
self.loadResponseText = function(responseText, textStatus, xhr) {
/* RemovedInWagtail24Warning - support for eval()-ing text/javascript responses
(rather than JSON.parse) will be dropped */
var response;
if (xhr && xhr.getResponseHeader('content-type') != 'text/javascript') {
response = JSON.parse(responseText);
} else {
response = eval('(' + responseText + ')');
}
var response = JSON.parse(responseText);
self.loadBody(response);
};
@ -74,12 +66,6 @@ function ModalWorkflow(opts) {
container.modal('show');
}
if (response.onload) {
// if response contains an 'onload' function, call it
// (passing this modal object and the full response data)
response.onload(self, response);
}
/* If response contains a 'step' identifier, and that identifier is found in
the onload dict, call that onload handler */
if (opts.onload && response.step && (response.step in opts.onload)) {