From 0eefc3dfd343b015114204997ab96c7123eaff78 Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 29 Sep 2011 17:13:07 +0000 Subject: [PATCH] in between queries default view/sort for lists --- pandora/item/managers.py | 10 ++++++- pandora/itemlist/models.py | 8 ++++-- pandora/itemlist/views.py | 54 ++++++++++++++++++++++---------------- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/pandora/item/managers.py b/pandora/item/managers.py index fd2fcaf7c..12714cea0 100644 --- a/pandora/item/managers.py +++ b/pandora/item/managers.py @@ -67,6 +67,10 @@ def parseCondition(condition): in_find = False facet_value = 'facets__value%s' % { '==': '__iexact', + '>': '__gt', + '>=': '__gte', + '<': '__lt', + '<=': '__lte', '^': '__istartswith', '$': '__iendswith', }.get(op, '__icontains') @@ -75,6 +79,10 @@ def parseCondition(condition): else: value_key = 'find__value%s' % { '==': '__iexact', + '>': '__gt', + '>=': '__gte', + '<': '__lt', + '<=': '__lte', '^': '__istartswith', '$': '__iendswith', }.get(op, '__icontains') @@ -131,7 +139,7 @@ def parseCondition(condition): }.get(op,'__exact')) vk = str('find__%s' % vk) - + if exclude: #!1960 return ~Q(**{'find__key': k, vk: v}) else: #1960 diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index fa48bb903..da41abd75 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -34,6 +34,9 @@ class List(models.Model): icon = models.ImageField(default=None, blank=True, upload_to=lambda i, x: i.path("icon.jpg")) + view = models.TextField(default=settings.CONFIG['user']['ui']['listView']) + sort = TupleField(default=tuple(settings.CONFIG['user']['ui']['listSort']), editable=False) + poster_frames = TupleField(default=[], editable=False) #is through table still required? @@ -50,7 +53,8 @@ class List(models.Model): self.type = 'static' else: self.type = 'smart' - self.items_sum = self.get_items_sum(self.user) + if self.id: + self.items_sum = self.get_items_sum(self.user) super(List, self).save(*args, **kwargs) def get_items_sum(self, user=None): @@ -144,7 +148,7 @@ class List(models.Model): if not os.path.exists(path): folder = os.path.dirname(path) ox.makedirs(folder) - if self.icon: + if self.icon and os.path.exists(self.icon.path): source = self.icon.path max_size = min(self.icon.width, self.icon.height) else: diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index 18641948c..1622001c0 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -192,6 +192,8 @@ def addList(request): type query items + view + sort return { status: {'code': int, 'text': string}, @@ -211,28 +213,32 @@ def addList(request): num += 1 name = data['name'] + ' [%d]' % num - for key in data: - if key == 'query' and not data['query']: - setattr(list, key, {"static":True}) - elif key == 'query': - setattr(list, key, data[key]) - elif key == 'type': - if data[key] == 'static': - list.query = {"static":True} - list.type = 'static' - else: - list.type = 'dynamic' - if list.query.get('static', False): - list.query = {} - elif key == 'status': - value = data[key] - if value not in list._status: - value = list._status[0] - if not request.user.is_staff and value == 'featured': - value = 'private' - setattr(list, key, value) - elif key == 'description': - list.description = data['description'] + if 'query' in data and data['query']: + setattr(list, 'query', data['query']) + else: + setattr(list, 'query', {"static":True}) + if 'type' in data: + if data['type'] == 'static': + list.query = {"static":True} + list.type = 'static' + else: + list.type = 'dynamic' + if list.query.get('static', False): + list.query = {} + if 'status' in data: + value = data['status'] + if value not in list._status: + value = list._status[0] + if not request.user.is_staff and value == 'featured': + value = 'private' + list.status = value + if 'description' in data: + list.description = data['description'] + if 'view' in data: + list.view = data['view'] + if 'sort' in data: + list.sort= tuple(data['sort']) + list.save() if 'items' in data: @@ -351,6 +357,10 @@ def editList(request): if 'posterFrames' in data: list.poster_frames = tuple(data['posterFrames']) list.update_icon() + if 'view' in data: + list.view = data['view'] + if 'sort' in data: + list.sort= tuple(data['sort']) list.save() response['data'] = list.json(user=request.user) else: