Fixes to render_modal_workflow

- RequestContext is deprecated
- Fixed  mutable dict as a default parameter
This commit is contained in:
Karl Hobley 2015-04-02 15:52:26 +01:00
parent 87cd93587e
commit 4ad856d0d8

View file

@ -1,24 +1,22 @@
import json
from django.http import HttpResponse
from django.template import RequestContext
from django.template.loader import render_to_string
def render_modal_workflow(request, html_template, js_template, template_vars={}):
def render_modal_workflow(request, html_template, js_template, template_vars=None):
""""
Render a response consisting of an HTML chunk and a JS onload chunk
in the format required by the modal-workflow framework.
"""
response_keyvars = []
context = RequestContext(request)
if html_template:
html = render_to_string(html_template, template_vars, context)
html = render_to_string(html_template, template_vars or {}, request=request)
response_keyvars.append("'html': %s" % json.dumps(html))
if js_template:
js = render_to_string(js_template, template_vars, context)
js = render_to_string(js_template, template_vars or {}, request=request)
response_keyvars.append("'onload': %s" % js)
response_text = "{%s}" % ','.join(response_keyvars)