mirror of
https://github.com/jazzband/django-eav2.git
synced 2026-03-16 22:40:26 +00:00
24 lines
762 B
Python
24 lines
762 B
Python
'''Utilities. This module contains non-essential helper methods.'''
|
|
|
|
import sys
|
|
|
|
from django.db.models import Q
|
|
|
|
|
|
def print_q_expr(expr, indent="", is_tail=True):
|
|
'''
|
|
Simple print method for debugging Q-expressions' trees.
|
|
'''
|
|
sys.stdout.write(indent)
|
|
sa, sb = (' └── ', ' ') if is_tail else (' ├── ', ' │ ')
|
|
|
|
if type(expr) == Q:
|
|
sys.stdout.write('{}{}\n'.format(sa, expr.connector))
|
|
for child in expr.children:
|
|
print_q_expr(child, indent + sb, expr.children[-1] == child)
|
|
else:
|
|
try:
|
|
queryset = ', '.join(repr(v) for v in expr[1])
|
|
except TypeError:
|
|
queryset = repr(expr[1])
|
|
sys.stdout.write(' └── {} {}\n'.format(expr[0], queryset))
|