forked from 0x2620/pandora
always use get_operator, avoid case-insensitive match if possible
This commit is contained in:
parent
5b545e6e43
commit
e9863c238e
24 changed files with 289 additions and 370 deletions
|
|
@ -4,15 +4,18 @@ from django.db.models import Q, Manager
|
|||
from oxdjango.query import QuerySet
|
||||
|
||||
from item.utils import decode_id
|
||||
from oxdjango.managers import get_operator
|
||||
|
||||
keymap = {
|
||||
'user': 'user__username',
|
||||
}
|
||||
default_key = 'name'
|
||||
|
||||
def parseCondition(condition, user):
|
||||
k = condition.get('key', 'name')
|
||||
k = {
|
||||
'user': 'user__username',
|
||||
}.get(k, k)
|
||||
k = condition.get('key', defauly_key)
|
||||
k = keymap.get(k, k)
|
||||
if not k:
|
||||
k = 'name'
|
||||
k = default_key
|
||||
v = condition['value']
|
||||
op = condition.get('operator')
|
||||
if not op:
|
||||
|
|
@ -31,26 +34,12 @@ def parseCondition(condition, user):
|
|||
return q
|
||||
if k == 'id':
|
||||
v = decode_id(v)
|
||||
if isinstance(v, bool): #featured and public flag
|
||||
if isinstance(v, bool):
|
||||
key = k
|
||||
elif k in ('id',):
|
||||
key = "%s%s" % (k, {
|
||||
'>': '__gt',
|
||||
'>=': '__gte',
|
||||
'<': '__lt',
|
||||
'<=': '__lte',
|
||||
}.get(op, ''))
|
||||
key = k + get_operator(op, 'int')
|
||||
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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue