From 97535240e88b3e5d723a7d1f7d619e785cee0422 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 14 Jan 2011 09:46:41 +0530 Subject: [PATCH] positions --- pandora/itemlist/views.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index 53c87b29b..6f36240d8 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -207,8 +207,9 @@ def addList(request): value = data[key] if value not in list._status: value = list._status[0] + if not user.request.is_staff and value == 'featured': + value = 'private' setattr(list, key, value) - list.save() pos, created = models.Position.objects.get_or_create(list=list, @@ -259,10 +260,25 @@ def editList(request): value = data[key] if value not in list._status: value = list._status[0] - setattr(list, key, value) if value == 'private': for user in list.subscribed_users.all(): list.subscribed_users.remove(user) + qs = models.Position.objects.filter(user=request.user, section='section', list=list) + if qs.count() > 1: + pos = qs[0] + pos.section = 'my' + pos.save() + elif value == 'featured': + if not request.user.is_staff: + value = list.status + else: + pos, created = models.Position.objects.get_or_create(list=list, user=request.user, + section='featured') + if created: + qs = models.Position.objects.filter(user=request.user, section='featured') + pos.position = qs.aggregate(Max('position'))['position__max'] + 1 + pos.save() + list.status = value elif key == 'name': name = data['name'].strip() if not name: @@ -271,7 +287,7 @@ def editList(request): while models.List.objects.filter(name=name, user=list.user).exclude(id=list.id).count()>0: num += 1 name = data['name'] + ' (%d)' % num - setattr(list, key, name) + list.name = name if 'position' in data: pos, created = models.Position.objects.get_or_create(list=list, user=request.user)