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

@ -2,12 +2,20 @@
# vi:si:et:sw=4:sts=4:ts=4
from django.db.models import Q, Manager
from oxdjango.query import QuerySet
from item.utils import decode_id
from oxdjango.managers import get_operator
from oxdjango.query import QuerySet
import models
keymap = {
'in': 'start',
'out': 'end'
}
case_insensitive_keys = ('user__username', 'subscribed_users__username')
default_key = 'name'
def parseCondition(condition, user):
'''
@ -21,13 +29,10 @@ def parseCondition(condition, user):
operator: "!="
}
'''
k = condition.get('key', 'name')
k = {
'in': 'start',
'out': 'end'
}.get(k, k)
k = condition.get('key', default_key)
k = keymap.get(k, k)
if not k:
k = 'name'
k = default_key
v = condition['value']
op = condition.get('operator')
if not op:
@ -47,31 +52,22 @@ def parseCondition(condition, user):
if k == 'id':
public_id, points = v.split('/')
points = [float('%0.03f'%float(p)) for p in points.split('-')]
points = [float('%0.03f' % float(p)) for p in points.split('-')]
q = Q(sort__item__public_id=public_id, start=points[0], end=points[1])
return exclude and ~q or q
if k == 'hash':
v = models.parse_hash(v)
v = models.parse_hash(v)
if k == 'mode':
v = models.Sequence.MODE[v]
if k.endswith('__id'):
v = decode_id(v)
if isinstance(v, bool): #featured and public flag
if isinstance(v, bool):
key = k
elif k in ('mode', 'hash'):
key = k
else:
if k in ('mode', 'hash'):
key = k
else:
key = "%s%s" % (k, {
'>': '__gt',
'>=': '__gte',
'<': '__lt',
'<=': '__lte',
'==': '__iexact',
'=': '__icontains',
'^': '__istartswith',
'$': '__iendswith',
}.get(op, '__icontains'))
key = k + get_operator(op, 'istr')
key = str(key)
if exclude: