support findUsers level conditions
This commit is contained in:
parent
c4ffa15bd4
commit
680cfc8981
1 changed files with 20 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
from django.db.models import Q, Manager
|
from django.db.models import Q, Manager
|
||||||
from ox.django.query import QuerySet
|
from ox.django.query import QuerySet
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
def parseCondition(condition, user):
|
def parseCondition(condition, user):
|
||||||
k = condition.get('key', 'name')
|
k = condition.get('key', 'name')
|
||||||
|
@ -19,17 +20,28 @@ def parseCondition(condition, user):
|
||||||
else:
|
else:
|
||||||
exclude = False
|
exclude = False
|
||||||
|
|
||||||
key = '%s%s' % (k, {
|
if k == 'level':
|
||||||
'==': '__iexact',
|
if v in settings.CONFIG['userLevels']:
|
||||||
'^': '__istartswith',
|
v = settings.CONFIG['userLevels'].index(v)
|
||||||
'$': '__iendswith',
|
else:
|
||||||
}.get(op,'__icontains'))
|
v = 0
|
||||||
|
key = '%s%s' % (k, {
|
||||||
|
'==': '__exact',
|
||||||
|
'<': '__lt',
|
||||||
|
'>': '__gt',
|
||||||
|
}.get(op,''))
|
||||||
|
else:
|
||||||
|
key = '%s%s' % (k, {
|
||||||
|
'==': '__iexact',
|
||||||
|
'^': '__istartswith',
|
||||||
|
'$': '__iendswith',
|
||||||
|
}.get(op,'__icontains'))
|
||||||
|
|
||||||
key = str(key)
|
key = str(key)
|
||||||
|
|
||||||
|
q = Q(**{key: v})
|
||||||
if exclude:
|
if exclude:
|
||||||
q = ~Q(**{key: v})
|
q = ~q
|
||||||
else:
|
|
||||||
q = Q(**{key: v})
|
|
||||||
return q
|
return q
|
||||||
|
|
||||||
def parseConditions(conditions, operator, user):
|
def parseConditions(conditions, operator, user):
|
||||||
|
|
Loading…
Reference in a new issue