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

View file

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

View file

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