lists.status

This commit is contained in:
j 2011-01-11 17:21:22 +05:30
parent 68fa703eb8
commit 83acfd78fc
3 changed files with 20 additions and 12 deletions

View file

@ -134,4 +134,5 @@ class ListManager(Manager):
if conditions: if conditions:
qs = qs.filter(conditions) qs = qs.filter(conditions)
qs = qs.filter(Q(status='public') | Q(status='featured') | Q(user=user))
return qs return qs

View file

@ -21,9 +21,9 @@ class List(models.Model):
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User) user = models.ForeignKey(User)
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
public = models.BooleanField(default=False) status = models.CharField(max_length=20, default='private')
featured = models.BooleanField(default=False) _status = ['private', 'public', 'featured']
query = DictField(default={}) query = DictField(default={"static": True})
items = models.ManyToManyField('item.Item', related_name='lists', items = models.ManyToManyField('item.Item', related_name='lists',
through='ListItem') through='ListItem')
@ -31,14 +31,10 @@ class List(models.Model):
objects = managers.ListManager() objects = managers.ListManager()
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if self.query:
self.smart = True
else:
self.smart = False
super(List, self).save(*args, **kwargs) super(List, self).save(*args, **kwargs)
def get_number_of_items(self, user=None): def get_number_of_items(self, user=None):
if not self.query: if self.query.get('static', False):
return self.items.count() return self.items.count()
else: else:
return Item.objects.find({'query': self.query}, user).count() 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) response[key] = self.get_number_of_items(user)
elif key == 'user': elif key == 'user':
response[key] = self.user.username response[key] = self.user.username
elif key == 'query':
if not self.query.get('static', False):
response[key] = self.query
else: else:
response[key] = getattr(self, key) response[key] = getattr(self, key)
return response return response

View file

@ -33,7 +33,7 @@ def _parse_query(data, user):
query['qs'] = models.List.objects.find(data, user) query['qs'] = models.List.objects.find(data, user)
return query return query
def findList(request): def findLists(request):
''' '''
FIXME: support key: subscribed FIXME: support key: subscribed
param data { param data {
@ -81,7 +81,7 @@ def findList(request):
else: else:
response['data']['items'] = qs.count() response['data']['items'] = qs.count()
return render_to_json_response(response) return render_to_json_response(response)
actions.register(findList) actions.register(findLists)
@login_required_json @login_required_json
def addListItem(request): def addListItem(request):
@ -189,9 +189,17 @@ def editList(request):
list = get_object_or_404_json(models.List, pk=data['list']) list = get_object_or_404_json(models.List, pk=data['list'])
if list.editable(request.user): if list.editable(request.user):
for key in data: for key in data:
if key in ('name', 'public', 'query'): if key in ('name', 'status', 'query'):
if key in data: 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: if user.has_perm('Ox.admin') and 'featured' in data:
list.featured = data['featured'] list.featured = data['featured']
else: else: