utils.py 503 B

123456789101112131415
  1. from django.template.context import RequestContext
  2. def get_context_dict(context):
  3. """
  4. Contexts in django version 1.9+ must be dictionaries. As xadmin has a legacy with older versions of django,
  5. the function helps the transition by converting the [RequestContext] object to the dictionary when necessary.
  6. :param context: RequestContext
  7. :return: dict
  8. """
  9. if isinstance(context, RequestContext):
  10. ctx = context.flatten()
  11. else:
  12. ctx = context
  13. return ctx