lists.status
This commit is contained in:
parent
68fa703eb8
commit
83acfd78fc
3 changed files with 20 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,8 +189,16 @@ 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:
|
||||
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']
|
||||
|
|
Loading…
Reference in a new issue