File: compat.py

package info (click to toggle)
drf-extensions 0.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,308 kB
  • sloc: python: 7,421; makefile: 11
file content (16 lines) | stat: -rw-r--r-- 559 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""
The `compat` module provides support for backwards compatibility with older
versions of django/python, and compatibility wrappers around optional packages.
"""


# handle different QuerySet representations
def queryset_to_value_list(queryset):
    assert isinstance(queryset, str)

    # django 1.10 introduces syntax "<QuerySet [(#1), (#2), ...]>"
    # we extract only the list of tuples from the string
    idx_bracket_open = queryset.find(u'[')
    idx_bracket_close = queryset.rfind(u']')

    return queryset[idx_bracket_open:idx_bracket_close + 1]