conditions
This commit is contained in:
parent
9eccc030a1
commit
a5158f1555
2 changed files with 37 additions and 40 deletions
|
@ -35,6 +35,14 @@ def parseCondition(condition):
|
||||||
else:
|
else:
|
||||||
exclude = False
|
exclude = False
|
||||||
|
|
||||||
|
if op == '-':
|
||||||
|
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}) \
|
||||||
|
& parseCondition({'key': k, 'value': v[1], 'operator': '<'})
|
||||||
|
if exclude:
|
||||||
|
return ~q
|
||||||
|
else:
|
||||||
|
return q
|
||||||
|
|
||||||
key_type = models.site_config()['keys'].get(k, {'type':'string'}).get('type')
|
key_type = models.site_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]
|
||||||
|
@ -53,7 +61,7 @@ def parseCondition(condition):
|
||||||
value_key = 'find__value'
|
value_key = 'find__value'
|
||||||
if k in models.Item.facet_keys:
|
if k in models.Item.facet_keys:
|
||||||
in_find = False
|
in_find = False
|
||||||
if op == '=':
|
if op == '=' or op == '^$':
|
||||||
v = models.Item.objects.filter(facets__key=k, facets__value=v)
|
v = models.Item.objects.filter(facets__key=k, facets__value=v)
|
||||||
elif op == '^':
|
elif op == '^':
|
||||||
v = models.Item.objects.filter(facets__key=k, facets__value__istartswith=v)
|
v = models.Item.objects.filter(facets__key=k, facets__value__istartswith=v)
|
||||||
|
@ -62,7 +70,7 @@ def parseCondition(condition):
|
||||||
else:
|
else:
|
||||||
v = models.Item.objects.filter(facets__key=k, facets__value__icontains=v)
|
v = models.Item.objects.filter(facets__key=k, facets__value__icontains=v)
|
||||||
k = 'id__in'
|
k = 'id__in'
|
||||||
elif op == '=':
|
elif op == '=' or op == '^$':
|
||||||
value_key = 'find__value__iexact'
|
value_key = 'find__value__iexact'
|
||||||
elif op == '^':
|
elif op == '^':
|
||||||
v = v[1:]
|
v = v[1:]
|
||||||
|
@ -108,25 +116,10 @@ def parseCondition(condition):
|
||||||
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 op == '-':
|
|
||||||
v1 = v[1]
|
|
||||||
v2 = v[2]
|
|
||||||
if key_type == "date":
|
|
||||||
v1 = parseDate(v1.split('.'))
|
|
||||||
v2 = parseDate(v2.split('.'))
|
|
||||||
|
|
||||||
if exclude: #!1960-1970
|
|
||||||
k1 = 'value__lt'
|
|
||||||
k2 = 'value__gte'
|
|
||||||
return Q(**{'find__key': k, k1: v1})|Q(**{'find__key': k, k2: v2})
|
|
||||||
else: #1960-1970
|
|
||||||
k1 = 'value__gte'
|
|
||||||
k2 = 'value__lt'
|
|
||||||
return Q(**{'find__key': k, k1: v1})&Q(**{'find__key': k, k2: v2})
|
|
||||||
else:
|
|
||||||
if key_type == "date":
|
if key_type == "date":
|
||||||
v = parseDate(v.split('.'))
|
v = parseDate(v.split('.'))
|
||||||
if op == '=':
|
if op == '=' or op == '^$':
|
||||||
vk = 'value__exact'
|
vk = 'value__exact'
|
||||||
elif op == '>':
|
elif op == '>':
|
||||||
vk = 'value__gt'
|
vk = 'value__gt'
|
||||||
|
|
|
@ -32,8 +32,12 @@ def parseCondition(condition, user):
|
||||||
else:
|
else:
|
||||||
exclude = False
|
exclude = False
|
||||||
if op == '-':
|
if op == '-':
|
||||||
return parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
|
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}) \
|
||||||
& parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
|
& parseCondition({'key': k, 'value': v[1], 'operator': '<'})
|
||||||
|
if exclude:
|
||||||
|
return ~q
|
||||||
|
else:
|
||||||
|
return q
|
||||||
if k == 'id':
|
if k == 'id':
|
||||||
v = v.split('/')
|
v = v.split('/')
|
||||||
if len(v) == 2:
|
if len(v) == 2:
|
||||||
|
@ -55,7 +59,7 @@ def parseCondition(condition, user):
|
||||||
else: #default is exact match
|
else: #default is exact match
|
||||||
key = k
|
key = k
|
||||||
else:
|
else:
|
||||||
if op == '=':
|
if op == '=' or op == '^$':
|
||||||
key = '%s__iexact'%k
|
key = '%s__iexact'%k
|
||||||
elif op == '^':
|
elif op == '^':
|
||||||
v = v[1:]
|
v = v[1:]
|
||||||
|
|
Loading…
Reference in a new issue