always use get_operator, avoid case-insensitive match if possible

This commit is contained in:
j 2016-06-29 23:58:29 +02:00
commit e9863c238e
24 changed files with 289 additions and 370 deletions

View file

@ -3,19 +3,21 @@
from django.db.models import Q, Manager
from oxdjango.query import QuerySet
from oxdjango.managers import get_operator
keymap = {
'user': 'user__username',
'position': 'position__position',
'posterFrames': 'poster_frames',
}
default_key = 'name'
def parseCondition(condition, user):
'''
'''
k = condition.get('key', 'name')
k = {
'user': 'user__username',
'position': 'position__position',
'posterFrames': 'poster_frames',
}.get(k, k)
k = condition.get('key', default_key)
k = keymap.get(k, k)
if not k:
k = 'name'
k = default_key
v = condition.get('value', '')
op = condition.get('operator')
if not op:
@ -36,14 +38,10 @@ def parseCondition(condition, user):
if k == 'subscribed':
key = 'subscribed_users__username'
v = user.username
elif isinstance(v, bool): #featured and public flag
elif isinstance(v, bool):
key = k
else:
key = "%s%s" % (k, {
'==': '__iexact',
'^': '__istartswith',
'$': '__iendswith',
}.get(op, '__icontains'))
key = k + get_operator(op, 'istr')
key = str(key)
if exclude:
q = ~Q(**{key: v})