From ccd0cc59369c6e5c431d05516dc6ed867b0c196a Mon Sep 17 00:00:00 2001 From: Thomas Willson Date: Mon, 21 Dec 2015 20:43:26 +0000 Subject: [PATCH 1/2] Update import for django.template.context_processors. Old import was deprecated in Django 1.8. --- jfu/templatetags/jfutags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jfu/templatetags/jfutags.py b/jfu/templatetags/jfutags.py index 5c3b806..9df4cac 100644 --- a/jfu/templatetags/jfutags.py +++ b/jfu/templatetags/jfutags.py @@ -1,4 +1,4 @@ -from django.core.context_processors import csrf +from django.template.context_processors import csrf from django.core.urlresolvers import reverse from django.template import Library, Context, loader From b5633c72a1573380619570b3eb3d3732edc882f7 Mon Sep 17 00:00:00 2001 From: Thomas Willson Date: Mon, 18 Jan 2016 10:53:13 -0800 Subject: [PATCH 2/2] Take care of Template.Render(Context()) deprecation in 1.9. See: https://github.com/django/django/blob/1.9rc1/django/template/backends/django.py#L64-L89 --- jfu/templatetags/jfutags.py | 41 +++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/jfu/templatetags/jfutags.py b/jfu/templatetags/jfutags.py index 9df4cac..36f7fcc 100644 --- a/jfu/templatetags/jfutags.py +++ b/jfu/templatetags/jfutags.py @@ -1,16 +1,18 @@ -from django.template.context_processors import csrf from django.core.urlresolvers import reverse from django.template import Library, Context, loader +from django.template.context_processors import csrf +import django register = Library() -@register.simple_tag( takes_context = True ) + +@register.simple_tag(takes_context=True) def jfu( - context, - template_name = 'jfu/upload_form.html', - upload_handler_name = 'jfu_upload', - *args, **kwargs - ): + context, + template_name='jfu/upload_form.html', + upload_handler_name='jfu_upload', + *args, **kwargs +): """ Displays a form for uploading files using jQuery File Upload. @@ -21,19 +23,28 @@ def jfu( Any additionally supplied positional and keyword arguments are directly forwarded to the named custom upload-handling URL. """ - context.update( { - 'JQ_OPEN' : '{%', - 'JQ_CLOSE' : '%}', + context.update({ + 'JQ_OPEN': '{%', + 'JQ_CLOSE': '%}', 'upload_handler_url': reverse( - upload_handler_name, args = args, kwargs = kwargs + upload_handler_name, args=args, kwargs=kwargs ), - } ) + }) # Use the request context variable, injected # by django.core.context_processors.request, # to generate the CSRF token. - context.update( csrf( context.get('request') ) ) + context.update(csrf(context.get('request'))) + + t = loader.get_template(template_name) - t = loader.get_template( template_name ) + # Calling Template.render() with a Context is deprecated. + # See: https://github.com/django/django/blob/1.9rc1/django/template/backends/django.py#L64-L89 + if django.VERSION >= (1, 8): + if isinstance(context, Context): + context = context.flatten() + else: + if not isinstance(context, Context): + context = Context(context) - return t.render( Context( context ) ) + return t.render(context)