my/personal

This commit is contained in:
j 2011-01-21 05:13:41 +00:00
parent 90710571c7
commit 1ac87d9653
3 changed files with 48 additions and 32 deletions

View file

@ -225,8 +225,8 @@ def addList(request):
qs = models.Position.objects.filter(section='featured')
else:
pos, created = models.Position.objects.get_or_create(list=list,
user=request.user, section='my')
qs = models.Position.objects.filter(user=request.user, section='my')
user=request.user, section='personal')
qs = models.Position.objects.filter(user=request.user, section='personal')
pos.position = qs.aggregate(Max('position'))['position__max'] + 1
pos.save()
response = json_response(status=200, text='created')
@ -278,7 +278,7 @@ def editList(request):
qs = models.Position.objects.filter(user=request.user, section='section', list=list)
if qs.count() > 1:
pos = qs[0]
pos.section = 'my'
pos.section = 'personal'
pos.save()
elif value == 'featured':
if not request.user.is_staff:
@ -293,9 +293,10 @@ def editList(request):
models.Position.objects.filter(list=list).exclude(id=pos.id).delete()
else:
models.Position.objects.filter(list=list).delete()
pos, created = models.Position.objects.get_or_create(list=list, user=list.user,
section='my')
qs = models.Position.objects.filter(user=list.user, section='my')
pos, created = models.Position.objects.get_or_create(list=list,
user=list.user,section='personal')
qs = models.Position.objects.filter(user=list.user,
section='personal')
pos.position = qs.aggregate(Max('position'))['position__max'] + 1
pos.save()
for u in list.subscribed_users.all():
@ -323,7 +324,7 @@ def editList(request):
pos.position = data['position']
pos.section = 'featured'
if list.status == 'private':
pos.section = 'my'
pos.section = 'personal'
pos.save()
list.save()
response['data'] = list.json(user=request.user)
@ -411,10 +412,10 @@ actions.register(unsubscribeFromList, cache=False)
def sortLists(request):
'''
param data {
section: 'my',
section: 'personal',
ids: [1,2,4,3]
}
known sections: 'my', 'public', 'featured'
known sections: 'personal', 'public', 'featured'
featured can only be edited by admins
return {
status: {'code': int, 'text': string},
@ -425,27 +426,29 @@ def sortLists(request):
data = json.loads(request.POST['data'])
position = 0
section = data['section']
#ids = list(set(data['ids']))
ids = data['ids']
if section == 'featured' and not request.user.is_staff:
response = json_response(status=403, text='not allowed')
else:
user = request.user
if section == 'featured':
for i in data['ids']:
list = get_list_or_404_json(i)
qs = models.Position.objects.filter(section=section, list=list)
for i in ids:
l = get_list_or_404_json(i)
qs = models.Position.objects.filter(section=section, list=l)
if qs.count() > 0:
pos = qs[0]
else:
pos = models.Position(list=list, user=user, section=section)
pos = models.Position(list=l, user=user, section=section)
if pos.position != position:
pos.position = position
pos.save()
position += 1
models.Position.objects.filter(section=section, list=list).exclude(id=pos.id).delete()
models.Position.objects.filter(section=section, list=l).exclude(id=pos.id).delete()
else:
for i in data['ids']:
list = get_list_or_404_json(i)
pos, created = models.Position.objects.get_or_create(list=list,
for i in ids:
l = get_list_or_404_json(i)
pos, created = models.Position.objects.get_or_create(list=l,
user=request.user, section=section)
if pos.position != position:
pos.position = position

View file

@ -67,11 +67,12 @@
"sectionName": "{{settings.SITENAME}}",
"url": "{{settings.URL}}"
},
"sections": [
{"id": "history", "title": "History"},
{"id": "my", "title": "My Lists"},
{"id": "public", "title": "Public Lists"},
{"id": "featured", "title": "Featured Lists"}
"sitePages": [
{"id": "about", "title": "About"},
{"id": "news", "title": "News"},
{"id": "tour", "title": "Take a Tour"},
{"id": "faq", "title": "Frequently Asked Questions"},
{"id": "tos", "title": "Terms of Service"}
],
"sortKeys": [
{"id": "title", "title": "Title", "width": 180, "removable": false, "type": "title"},
@ -131,14 +132,14 @@
"history": [
{"id": "all_movies", "title": "All Movies", "query": {}}
],
"my": [
"personal": [
{"user": "foo", "name": "Favorites", "featured": false, "public": true},
{"id": "favorites", "title": "Favorites", "public": true, "items": []},
{"id": "most_popular", "title": "Most Popular", "query": {}},
{"id": "recently_viewed", "title": "Recently Viewed", "query": {}},
{"id": "1960s", "title": "1960s", "query": {"conditions": [{"key": "year", "value": "196", "operator": "^"}], "operator": ""}}
],
"public": [
"favorite": [
{"id": "rlx:watchme", "title": "rlx: watchme", "public": true, "items": [0, 1, 2, 3, 4]}
],
"featured": [
@ -170,16 +171,22 @@
}
},
"section": "items",
"sections": ["my", "public", "featured"],
"showAnnotations": true,
"showControls": true,
"showGroups": true,
"showInfo": true,
"showMovies": true,
"showSection": {
"my": true,
"public": true,
"showFolder": {
"site": {
"site": true,
"user": true,
"admin": true
},
"items": {
"personal": true,
"favorite": true,
"featured": true
}
},
"showSidebar": true,
"sidebarSize": 256,

View file

@ -53,7 +53,13 @@ class UserProfile(models.Model):
for l in lists:
qs = Position.objects.filter(section=section)
if section == 'featured':
pos, created = Position.objects.get_or_create(list=l, section=section)
try:
pos = Position.objects.get(list=l, section=section)
created = False
except Position.DoesNotExist:
pos = Position(list=l, section=section, user=self.user)
pos.save()
created = True
else:
pos, created = Position.objects.get_or_create(list=l, user=self.user, section=section)
qs = qs.filter(user=self.user)
@ -70,8 +76,8 @@ class UserProfile(models.Model):
return ids
ids = ['']
ids += add(self.user.lists.exclude(status="featured"), 'my')
ids += add(self.user.subscribed_lists.all(), 'public')
ids += add(self.user.lists.exclude(status="featured"), 'personal')
ids += add(self.user.subscribed_lists.filter(status='public'), 'public')
ids += add(List.objects.filter(status='featured'), 'featured')
for i in ui['lists'].keys():
if i not in ids: