Skip to content

Commit

Permalink
Convert Context to dict.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsilva committed Dec 16, 2020
1 parent 73e78fa commit 3bde9f5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions xadmin/plugins/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from django.template.context import RequestContext
from django.template.context import RequestContext, Context


def get_context_dict(context):
"""
Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django,
the function helps the transition by converting the [RequestContext] object to the dictionary when necessary.
the function helps the transition by converting the [RequestContext, Context] object to the dictionary when necessary.
:param context: RequestContext
:return: dict
"""
if isinstance(context, RequestContext):
ctx = context.flatten()
elif isinstance(context, Context):
ctx = context.flatten()
else:
ctx = context
return ctx

0 comments on commit 3bde9f5

Please sign in to comment.