some work on advanced find
This commit is contained in:
parent
b6f5b45154
commit
4f61bf466e
2 changed files with 50 additions and 54 deletions
|
@ -115,7 +115,7 @@
|
||||||
{
|
{
|
||||||
"id": "year",
|
"id": "year",
|
||||||
"title": "Year",
|
"title": "Year",
|
||||||
"type": "year", // fixme: do we need this?
|
"type": "year",
|
||||||
"autocomplete": true,
|
"autocomplete": true,
|
||||||
"columnWidth": 60,
|
"columnWidth": 60,
|
||||||
"filter": true,
|
"filter": true,
|
||||||
|
|
|
@ -37,21 +37,6 @@ def parseCondition(condition, user):
|
||||||
else:
|
else:
|
||||||
exclude = False
|
exclude = False
|
||||||
|
|
||||||
if isinstance(v, list):
|
|
||||||
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
|
|
||||||
& parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
|
|
||||||
if exclude:
|
|
||||||
return ~q
|
|
||||||
else:
|
|
||||||
return q
|
|
||||||
|
|
||||||
if (not exclude and op == '=' or op in ('$', '^')) and v == '':
|
|
||||||
return Q()
|
|
||||||
|
|
||||||
if k == 'filename' and (user.is_anonymous() or \
|
|
||||||
not user.get_profile().capability('canSeeFiles')):
|
|
||||||
return Q(id=0)
|
|
||||||
|
|
||||||
key_type = settings.CONFIG['keys'].get(k, {'type':'string'}).get('type')
|
key_type = settings.CONFIG['keys'].get(k, {'type':'string'}).get('type')
|
||||||
if isinstance(key_type, list):
|
if isinstance(key_type, list):
|
||||||
key_type = key_type[0]
|
key_type = key_type[0]
|
||||||
|
@ -66,10 +51,19 @@ def parseCondition(condition, user):
|
||||||
}.get(key_type, key_type)
|
}.get(key_type, key_type)
|
||||||
if k == 'list':
|
if k == 'list':
|
||||||
key_type = 'list'
|
key_type = 'list'
|
||||||
if k in ('isSeries', ):
|
|
||||||
key_type = 'bool'
|
|
||||||
|
|
||||||
if k in ('canPlayVideo', 'canPlayClips'):
|
if (not exclude and op == '=' or op in ('$', '^')) and v == '':
|
||||||
|
return Q()
|
||||||
|
elif k == 'filename' and (user.is_anonymous() or \
|
||||||
|
not user.get_profile().capability('canSeeFiles')):
|
||||||
|
return Q(id=0)
|
||||||
|
elif isinstance(v, list) and len(v) == 2:
|
||||||
|
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
|
||||||
|
& parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
|
||||||
|
if exclude:
|
||||||
|
q = ~q
|
||||||
|
return q
|
||||||
|
elif k in ('canPlayVideo', 'canPlayClips'):
|
||||||
level = user.is_anonymous() and 'guest' or user.get_profile().get_level()
|
level = user.is_anonymous() and 'guest' or user.get_profile().get_level()
|
||||||
allowed_level = settings.CONFIG['capabilities'][k][level]
|
allowed_level = settings.CONFIG['capabilities'][k][level]
|
||||||
if v:
|
if v:
|
||||||
|
@ -79,7 +73,7 @@ def parseCondition(condition, user):
|
||||||
if exclude:
|
if exclude:
|
||||||
q = ~q
|
q = ~q
|
||||||
return q
|
return q
|
||||||
elif key_type == 'bool':
|
elif key_type == 'boolean':
|
||||||
q = Q(**{'find__key': k, 'find__value': v and '1' or '0'})
|
q = Q(**{'find__key': k, 'find__value': v and '1' or '0'})
|
||||||
if exclude:
|
if exclude:
|
||||||
q = ~q
|
q = ~q
|
||||||
|
@ -116,20 +110,14 @@ def parseCondition(condition, user):
|
||||||
|
|
||||||
k = str(k)
|
k = str(k)
|
||||||
value_key = str(value_key)
|
value_key = str(value_key)
|
||||||
if exclude:
|
|
||||||
if k == '*':
|
|
||||||
q = ~Q(**{value_key: v})
|
|
||||||
elif in_find:
|
|
||||||
q = ~Q(**{'find__key': k, value_key: v})
|
|
||||||
else:
|
|
||||||
q = ~Q(**{value_key: v})
|
|
||||||
else:
|
|
||||||
if k == '*':
|
if k == '*':
|
||||||
q = Q(**{value_key: v})
|
q = Q(**{value_key: v})
|
||||||
elif in_find:
|
elif in_find:
|
||||||
q = Q(**{'find__key': k, value_key: v})
|
q = Q(**{'find__key': k, value_key: v})
|
||||||
else:
|
else:
|
||||||
q = Q(**{value_key: v})
|
q = Q(**{value_key: v})
|
||||||
|
if exclude:
|
||||||
|
q = ~q
|
||||||
return q
|
return q
|
||||||
elif key_type == 'list':
|
elif key_type == 'list':
|
||||||
q = Q(id=0)
|
q = Q(id=0)
|
||||||
|
@ -151,17 +139,27 @@ def parseCondition(condition, user):
|
||||||
else:
|
else:
|
||||||
q = Q(id=0)
|
q = Q(id=0)
|
||||||
return q
|
return q
|
||||||
else: #number or date
|
elif key_type == 'date':
|
||||||
|
|
||||||
def parseDate(d):
|
def parseDate(d):
|
||||||
while len(d) < 3:
|
while len(d) < 3:
|
||||||
d.append(1)
|
d.append(1)
|
||||||
return datetime(*[int(i) for i in d])
|
return datetime(*[int(i) for i in d])
|
||||||
|
|
||||||
if key_type == "date":
|
#using sort here since find only contains strings
|
||||||
v = parseDate(v.split('.'))
|
v = parseDate(v.split('-'))
|
||||||
else:
|
vk = 'sort__%s%s' % (k, {
|
||||||
vk = 'value%s' % ({
|
'==': '__exact',
|
||||||
|
'>': '__gt',
|
||||||
|
'>=': '__gte',
|
||||||
|
'<': '__lt',
|
||||||
|
'<=': '__lte',
|
||||||
|
}.get(op,''))
|
||||||
|
q = Q(**{vk: v})
|
||||||
|
if exclude:
|
||||||
|
q = ~q
|
||||||
|
return q
|
||||||
|
else: #number
|
||||||
|
vk = 'find__value%s' % ({
|
||||||
'==': '__exact',
|
'==': '__exact',
|
||||||
'>': '__gt',
|
'>': '__gt',
|
||||||
'>=': '__gte',
|
'>=': '__gte',
|
||||||
|
@ -170,14 +168,12 @@ def parseCondition(condition, user):
|
||||||
'^': '__istartswith',
|
'^': '__istartswith',
|
||||||
'$': '__iendswith',
|
'$': '__iendswith',
|
||||||
}.get(op,'__exact'))
|
}.get(op,'__exact'))
|
||||||
|
vk = str(vk)
|
||||||
|
|
||||||
vk = str('find__%s' % vk)
|
q = Q(**{'find__key': k, vk: v})
|
||||||
|
if exclude:
|
||||||
if exclude: #!1960
|
q = ~q
|
||||||
return ~Q(**{'find__key': k, vk: v})
|
return q
|
||||||
else: #1960
|
|
||||||
return Q(**{'find__key': k, vk: v})
|
|
||||||
|
|
||||||
|
|
||||||
def parseConditions(conditions, operator, user):
|
def parseConditions(conditions, operator, user):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue