mirror of
https://github.com/jazzband/django-eav2.git
synced 2026-03-16 22:40:26 +00:00
* Add debug Q-expr print function * Change old __unicode__ methods to __str__ format * Move __unicode__ methods to __str__ * Rewrite AND Q-expressions to safe form * Make Q-expr debug print method use nicer format * Document rewrite_q_expr function * Rewrite/improve queries' test * Document some more code * Reorganize and document queryset module * Add more tests for queries * Use generic relation attribute instead instead of 'eav_values' * Update docstring * Fix a typo * Move up a variable * Rename a function * Check if 'in' filter rhs is not a QuerySet * Add newline to the end of file * Fix typo; tweak docstring
21 lines
692 B
Python
21 lines
692 B
Python
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))
|