kopia lustrzana https://github.com/wagtail/wagtail
Remove deprecated js_template handling from modal workflow
rodzic
771eb42d05
commit
65fb1e9cd4
|
@ -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)
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Ładowanie…
Reference in New Issue