Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update import for django.template.context_processors. #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions jfu/templatetags/jfutags.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from django.core.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.

Expand All @@ -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)