From a6a285367b1b1e41858445ef6c9f1fcf8f69962a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 22 Sep 2011 04:01:26 +0000 Subject: [PATCH] tune find query to match new url controler list names use : as seperator now --- pandora/item/managers.py | 20 +++++++++----------- pandora/itemlist/managers.py | 2 +- pandora/itemlist/models.py | 2 +- pandora/itemlist/views.py | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pandora/item/managers.py b/pandora/item/managers.py index beffc51c4..429de901b 100644 --- a/pandora/item/managers.py +++ b/pandora/item/managers.py @@ -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 diff --git a/pandora/itemlist/managers.py b/pandora/itemlist/managers.py index d1b4c3cf3..48917a2c5 100644 --- a/pandora/itemlist/managers.py +++ b/pandora/itemlist/managers.py @@ -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: diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index 6c66be98f..90e33e17c 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -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 diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index d8231dce6..614973fc6 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -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):