forked from 0x2620/pandora
even more lists stuff
This commit is contained in:
parent
3a2ae103b4
commit
2faa86065d
3 changed files with 320 additions and 207 deletions
|
|
@ -352,17 +352,19 @@ def subscribeToList(request):
|
|||
data = json.loads(request.POST['data'])
|
||||
list = get_list_or_404_json(data['id'])
|
||||
user = request.user
|
||||
if list.subscribed_users.filter(username=user.username).count() == 0:
|
||||
if list.status == 'public' and \
|
||||
list.subscribed_users.filter(username=user.username).count() == 0:
|
||||
list.subscribed_users.add(user)
|
||||
pos, created = models.Position.objects.get_or_create(list=list, user=request.user, section='public')
|
||||
pos, created = models.Position.objects.get_or_create(list=list, user=user, section='public')
|
||||
if created:
|
||||
qs = models.Position.objects.filter(user=request.user, section='public')
|
||||
qs = models.Position.objects.filter(user=user, section='public')
|
||||
pos.position = qs.aggregate(Max('position'))['position__max'] + 1
|
||||
pos.save()
|
||||
response = json_response()
|
||||
return render_to_json_response(response)
|
||||
actions.register(subscribeToList, cache=False)
|
||||
|
||||
|
||||
@login_required_json
|
||||
def unsubscribeFromList(request):
|
||||
'''
|
||||
|
|
@ -380,7 +382,7 @@ def unsubscribeFromList(request):
|
|||
list = get_list_or_404_json(data['id'])
|
||||
user = request.user
|
||||
list.subscribed_users.remove(user)
|
||||
models.Position.objects.filter(list=list, user=request.user, section='public').delete()
|
||||
models.Position.objects.filter(list=list, user=user, section='public').delete()
|
||||
response = json_response()
|
||||
return render_to_json_response(response)
|
||||
actions.register(unsubscribeFromList, cache=False)
|
||||
|
|
@ -416,8 +418,9 @@ def sortLists(request):
|
|||
pos = qs[0]
|
||||
else:
|
||||
pos = models.Position(list=list, user=user, section=section)
|
||||
pos.position = position
|
||||
pos.save()
|
||||
if pos.position != position:
|
||||
pos.position = position
|
||||
pos.save()
|
||||
position += 1
|
||||
models.Position.objects.filter(section=section, list=list).exclude(id=pos.id).delete()
|
||||
else:
|
||||
|
|
@ -425,8 +428,9 @@ def sortLists(request):
|
|||
list = get_list_or_404_json(i)
|
||||
pos, created = models.Position.objects.get_or_create(list=list,
|
||||
user=request.user, section=section)
|
||||
pos.position = position
|
||||
pos.save()
|
||||
if pos.position != position:
|
||||
pos.position = position
|
||||
pos.save()
|
||||
position += 1
|
||||
|
||||
response = json_response()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from datetime import datetime
|
|||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.db.models import Max
|
||||
from django.conf import settings
|
||||
|
||||
from ox.utils import json
|
||||
|
|
@ -39,12 +40,14 @@ class UserProfile(models.Model):
|
|||
def add(lists, section):
|
||||
ids = []
|
||||
for l in lists:
|
||||
qs = Position.objects.filter(section=section)
|
||||
if section == 'featured':
|
||||
pos, created = Position.objects.get_or_create(list=l, section=section)
|
||||
else:
|
||||
pos, created = Position.objects.get_or_create(list=l, user=self.user, section=section)
|
||||
qs = qs.filter(user=self.user)
|
||||
if created:
|
||||
pos.position = len(in_list)
|
||||
pos.position = qs.aggregate(Max('position'))['position__max'] + 1
|
||||
pos.save()
|
||||
id = l.get_id()
|
||||
if id not in ui['lists']:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue