conditions
This commit is contained in:
parent
abb6f82b80
commit
0bc14bb408
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,44 +116,29 @@ 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
|
if key_type == "date":
|
||||||
k1 = 'value__lt'
|
v = parseDate(v.split('.'))
|
||||||
k2 = 'value__gte'
|
if op == '=' or op == '^$':
|
||||||
return Q(**{'find__key': k, k1: v1})|Q(**{'find__key': k, k2: v2})
|
vk = 'value__exact'
|
||||||
else: #1960-1970
|
elif op == '>':
|
||||||
k1 = 'value__gte'
|
vk = 'value__gt'
|
||||||
k2 = 'value__lt'
|
elif op == '>=':
|
||||||
return Q(**{'find__key': k, k1: v1})&Q(**{'find__key': k, k2: v2})
|
vk = 'value__gte'
|
||||||
else:
|
elif op == '<':
|
||||||
if key_type == "date":
|
vk = 'value__lt'
|
||||||
v = parseDate(v.split('.'))
|
elif op == '<=':
|
||||||
if op == '=':
|
vk = 'value__lte'
|
||||||
vk = 'value__exact'
|
elif op == '':
|
||||||
elif op == '>':
|
vk = 'value__exact'
|
||||||
vk = 'value__gt'
|
|
||||||
elif op == '>=':
|
|
||||||
vk = 'value__gte'
|
|
||||||
elif op == '<':
|
|
||||||
vk = 'value__lt'
|
|
||||||
elif op == '<=':
|
|
||||||
vk = 'value__lte'
|
|
||||||
elif op == '':
|
|
||||||
vk = 'value__exact'
|
|
||||||
|
|
||||||
vk = 'find__%s' % vk
|
vk = 'find__%s' % vk
|
||||||
vk = str(vk)
|
vk = str(vk)
|
||||||
|
|
||||||
if exclude: #!1960
|
if exclude: #!1960
|
||||||
return ~Q(**{'find__key': k, vk: v})
|
return ~Q(**{'find__key': k, vk: v})
|
||||||
else: #1960
|
else: #1960
|
||||||
return Q(**{'find__key': k, vk: v})
|
return Q(**{'find__key': k, vk: v})
|
||||||
|
|
||||||
|
|
||||||
def parseConditions(conditions, operator):
|
def parseConditions(conditions, operator):
|
||||||
|
|
|
@ -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