tune find query to match new url controler

list names use : as seperator now
This commit is contained in:
j 2011-09-22 04:01:26 +00:00
parent ee4bfa0366
commit a6a285367b
4 changed files with 12 additions and 14 deletions

View file

@ -30,14 +30,14 @@ def parseCondition(condition):
v = condition['value']
op = condition.get('operator')
if not op:
op = ''
op = '='
if op.startswith('!'):
op = op[1:]
exclude = True
else:
exclude = False
if op == '-':
if isinstance(v, list):
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}) \
& parseCondition({'key': k, 'value': v[1], 'operator': '<'})
if exclude:
@ -65,7 +65,7 @@ def parseCondition(condition):
value_key = 'find__value'
if k in models.Item.facet_keys + ['title']:
in_find = False
if op == '=' or op == '^$':
if op == '==':
v = models.Item.objects.filter(facets__key=k, facets__value=v)
elif op == '^':
v = models.Item.objects.filter(facets__key=k, facets__value__istartswith=v)
@ -74,26 +74,24 @@ def parseCondition(condition):
else:
v = models.Item.objects.filter(facets__key=k, facets__value__icontains=v)
k = 'id__in'
elif op == '=' or op == '^$':
elif op == '==':
value_key = 'find__value__iexact'
elif op == '^':
v = v[1:]
value_key = 'find__value__istartswith'
elif op == '$':
v = v[:-1]
value_key = 'find__value__iendswith'
else: # default
value_key = 'find__value__icontains'
k = str(k)
if exclude:
if k == 'all':
if k == '*':
q = ~Q(**{value_key: v})
elif in_find and not k.startswith('itemId'):
q = ~Q(**{'find__key': k, value_key: v})
else:
q = ~Q(**{k: v})
else:
if k == 'all':
if k == '*':
q = Q(**{value_key: v})
elif in_find and not k.startswith('itemId'):
q = Q(**{'find__key': k, value_key: v})
@ -102,7 +100,7 @@ def parseCondition(condition):
return q
elif key_type == 'list':
q = Q(itemId=False)
l = v.split("/")
l = v.split(":")
if len(l) == 2:
lqs = list(List.objects.filter(name=l[1], user__username=l[0]))
if len(lqs) == 1:
@ -123,7 +121,7 @@ def parseCondition(condition):
if key_type == "date":
v = parseDate(v.split('.'))
if op == '=' or op == '^$':
if op == '==':
vk = 'value__exact'
elif op == '>':
vk = 'value__gt'
@ -133,7 +131,7 @@ def parseCondition(condition):
vk = 'value__lt'
elif op == '<=':
vk = 'value__lte'
elif op == '':
else:
vk = 'value__exact'
vk = 'find__%s' % vk

View file

@ -37,7 +37,7 @@ def parseCondition(condition, user):
else:
exclude = False
if k == 'id':
v = v.split('/')
v = v.split(':')
if len(v) == 2:
q = Q(user__username=v[0], name=v[1])
else:

View file

@ -68,7 +68,7 @@ class List(models.Model):
return self.get_id()
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):
#FIXME: make permissions work

View file

@ -13,7 +13,7 @@ from item import utils
from item.models import Item
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)
def _order_query(qs, sort):