support findUsers level conditions

This commit is contained in:
j 2011-11-12 14:10:52 +01:00
parent c4ffa15bd4
commit 680cfc8981

View file

@ -2,6 +2,7 @@
# vi:si:et:sw=4:sts=4:ts=4
from django.db.models import Q, Manager
from ox.django.query import QuerySet
from django.conf import settings
def parseCondition(condition, user):
k = condition.get('key', 'name')
@ -19,6 +20,17 @@ def parseCondition(condition, user):
else:
exclude = False
if k == 'level':
if v in settings.CONFIG['userLevels']:
v = settings.CONFIG['userLevels'].index(v)
else:
v = 0
key = '%s%s' % (k, {
'==': '__exact',
'<': '__lt',
'>': '__gt',
}.get(op,''))
else:
key = '%s%s' % (k, {
'==': '__iexact',
'^': '__istartswith',
@ -26,10 +38,10 @@ def parseCondition(condition, user):
}.get(op,'__icontains'))
key = str(key)
if exclude:
q = ~Q(**{key: v})
else:
q = Q(**{key: v})
if exclude:
q = ~q
return q
def parseConditions(conditions, operator, user):