From 83acfd78fcbf987ff0bf6db59fa8d28056c571aa Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 11 Jan 2011 17:21:22 +0530 Subject: [PATCH] lists.status --- pandora/itemlist/managers.py | 1 + pandora/itemlist/models.py | 15 +++++++-------- pandora/itemlist/views.py | 16 ++++++++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pandora/itemlist/managers.py b/pandora/itemlist/managers.py index e7c2cc543..280d94247 100644 --- a/pandora/itemlist/managers.py +++ b/pandora/itemlist/managers.py @@ -134,4 +134,5 @@ class ListManager(Manager): if conditions: qs = qs.filter(conditions) + qs = qs.filter(Q(status='public') | Q(status='featured') | Q(user=user)) return qs diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index b00047709..e886aa6ed 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -21,9 +21,9 @@ class List(models.Model): modified = models.DateTimeField(auto_now=True) user = models.ForeignKey(User) name = models.CharField(max_length=255) - public = models.BooleanField(default=False) - featured = models.BooleanField(default=False) - query = DictField(default={}) + status = models.CharField(max_length=20, default='private') + _status = ['private', 'public', 'featured'] + query = DictField(default={"static": True}) items = models.ManyToManyField('item.Item', related_name='lists', through='ListItem') @@ -31,14 +31,10 @@ class List(models.Model): objects = managers.ListManager() def save(self, *args, **kwargs): - if self.query: - self.smart = True - else: - self.smart = False super(List, self).save(*args, **kwargs) def get_number_of_items(self, user=None): - if not self.query: + if self.query.get('static', False): return self.items.count() else: return Item.objects.find({'query': self.query}, user).count() @@ -70,6 +66,9 @@ class List(models.Model): response[key] = self.get_number_of_items(user) elif key == 'user': response[key] = self.user.username + elif key == 'query': + if not self.query.get('static', False): + response[key] = self.query else: response[key] = getattr(self, key) return response diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index 4fea6ba03..169feb2f8 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -33,7 +33,7 @@ def _parse_query(data, user): query['qs'] = models.List.objects.find(data, user) return query -def findList(request): +def findLists(request): ''' FIXME: support key: subscribed param data { @@ -81,7 +81,7 @@ def findList(request): else: response['data']['items'] = qs.count() return render_to_json_response(response) -actions.register(findList) +actions.register(findLists) @login_required_json def addListItem(request): @@ -189,9 +189,17 @@ def editList(request): list = get_object_or_404_json(models.List, pk=data['list']) if list.editable(request.user): for key in data: - if key in ('name', 'public', 'query'): + if key in ('name', 'status', 'query'): if key in data: - setattr(list, key, data[key]) + if key == 'query' and not data['query']: + setattr(list, key, {"static":True}) + elif key == 'status': + value = data[key] + if value not in list._status: + value = list._status[0] + setattr(list, key, value) + else: + setattr(list, key, data[key]) if user.has_perm('Ox.admin') and 'featured' in data: list.featured = data['featured'] else: