tune find query to match new url controler
list names use : as seperator now
This commit is contained in:
parent
ee4bfa0366
commit
a6a285367b
4 changed files with 12 additions and 14 deletions
|
@ -30,14 +30,14 @@ def parseCondition(condition):
|
||||||
v = condition['value']
|
v = condition['value']
|
||||||
op = condition.get('operator')
|
op = condition.get('operator')
|
||||||
if not op:
|
if not op:
|
||||||
op = ''
|
op = '='
|
||||||
if op.startswith('!'):
|
if op.startswith('!'):
|
||||||
op = op[1:]
|
op = op[1:]
|
||||||
exclude = True
|
exclude = True
|
||||||
else:
|
else:
|
||||||
exclude = False
|
exclude = False
|
||||||
|
|
||||||
if op == '-':
|
if isinstance(v, list):
|
||||||
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}) \
|
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}) \
|
||||||
& parseCondition({'key': k, 'value': v[1], 'operator': '<'})
|
& parseCondition({'key': k, 'value': v[1], 'operator': '<'})
|
||||||
if exclude:
|
if exclude:
|
||||||
|
@ -65,7 +65,7 @@ def parseCondition(condition):
|
||||||
value_key = 'find__value'
|
value_key = 'find__value'
|
||||||
if k in models.Item.facet_keys + ['title']:
|
if k in models.Item.facet_keys + ['title']:
|
||||||
in_find = False
|
in_find = False
|
||||||
if op == '=' or op == '^$':
|
if 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)
|
||||||
|
@ -74,26 +74,24 @@ 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 == '=' or op == '^$':
|
elif op == '==':
|
||||||
value_key = 'find__value__iexact'
|
value_key = 'find__value__iexact'
|
||||||
elif op == '^':
|
elif op == '^':
|
||||||
v = v[1:]
|
|
||||||
value_key = 'find__value__istartswith'
|
value_key = 'find__value__istartswith'
|
||||||
elif op == '$':
|
elif op == '$':
|
||||||
v = v[:-1]
|
|
||||||
value_key = 'find__value__iendswith'
|
value_key = 'find__value__iendswith'
|
||||||
else: # default
|
else: # default
|
||||||
value_key = 'find__value__icontains'
|
value_key = 'find__value__icontains'
|
||||||
k = str(k)
|
k = str(k)
|
||||||
if exclude:
|
if exclude:
|
||||||
if k == 'all':
|
if k == '*':
|
||||||
q = ~Q(**{value_key: v})
|
q = ~Q(**{value_key: v})
|
||||||
elif in_find and not k.startswith('itemId'):
|
elif in_find and not k.startswith('itemId'):
|
||||||
q = ~Q(**{'find__key': k, value_key: v})
|
q = ~Q(**{'find__key': k, value_key: v})
|
||||||
else:
|
else:
|
||||||
q = ~Q(**{k: v})
|
q = ~Q(**{k: v})
|
||||||
else:
|
else:
|
||||||
if k == 'all':
|
if k == '*':
|
||||||
q = Q(**{value_key: v})
|
q = Q(**{value_key: v})
|
||||||
elif in_find and not k.startswith('itemId'):
|
elif in_find and not k.startswith('itemId'):
|
||||||
q = Q(**{'find__key': k, value_key: v})
|
q = Q(**{'find__key': k, value_key: v})
|
||||||
|
@ -102,7 +100,7 @@ def parseCondition(condition):
|
||||||
return q
|
return q
|
||||||
elif key_type == 'list':
|
elif key_type == 'list':
|
||||||
q = Q(itemId=False)
|
q = Q(itemId=False)
|
||||||
l = v.split("/")
|
l = v.split(":")
|
||||||
if len(l) == 2:
|
if len(l) == 2:
|
||||||
lqs = list(List.objects.filter(name=l[1], user__username=l[0]))
|
lqs = list(List.objects.filter(name=l[1], user__username=l[0]))
|
||||||
if len(lqs) == 1:
|
if len(lqs) == 1:
|
||||||
|
@ -123,7 +121,7 @@ def parseCondition(condition):
|
||||||
|
|
||||||
if key_type == "date":
|
if key_type == "date":
|
||||||
v = parseDate(v.split('.'))
|
v = parseDate(v.split('.'))
|
||||||
if op == '=' or op == '^$':
|
if op == '==':
|
||||||
vk = 'value__exact'
|
vk = 'value__exact'
|
||||||
elif op == '>':
|
elif op == '>':
|
||||||
vk = 'value__gt'
|
vk = 'value__gt'
|
||||||
|
@ -133,7 +131,7 @@ def parseCondition(condition):
|
||||||
vk = 'value__lt'
|
vk = 'value__lt'
|
||||||
elif op == '<=':
|
elif op == '<=':
|
||||||
vk = 'value__lte'
|
vk = 'value__lte'
|
||||||
elif op == '':
|
else:
|
||||||
vk = 'value__exact'
|
vk = 'value__exact'
|
||||||
|
|
||||||
vk = 'find__%s' % vk
|
vk = 'find__%s' % vk
|
||||||
|
|
|
@ -37,7 +37,7 @@ def parseCondition(condition, user):
|
||||||
else:
|
else:
|
||||||
exclude = False
|
exclude = False
|
||||||
if k == 'id':
|
if k == 'id':
|
||||||
v = v.split('/')
|
v = v.split(':')
|
||||||
if len(v) == 2:
|
if len(v) == 2:
|
||||||
q = Q(user__username=v[0], name=v[1])
|
q = Q(user__username=v[0], name=v[1])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -68,7 +68,7 @@ class List(models.Model):
|
||||||
return self.get_id()
|
return self.get_id()
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return u'%s/%s' % (self.user.username, self.name)
|
return u'%s:%s' % (self.user.username, self.name)
|
||||||
|
|
||||||
def editable(self, user):
|
def editable(self, user):
|
||||||
#FIXME: make permissions work
|
#FIXME: make permissions work
|
||||||
|
|
|
@ -13,7 +13,7 @@ from item import utils
|
||||||
from item.models import Item
|
from item.models import Item
|
||||||
|
|
||||||
def get_list_or_404_json(id):
|
def get_list_or_404_json(id):
|
||||||
username, listname = id.split('/')
|
username, listname = id.split(':')
|
||||||
return get_object_or_404_json(models.List, user__username=username, name=listname)
|
return get_object_or_404_json(models.List, user__username=username, name=listname)
|
||||||
|
|
||||||
def _order_query(qs, sort):
|
def _order_query(qs, sort):
|
||||||
|
|
Loading…
Reference in a new issue