save numberoflists in session table, fixes #687
This commit is contained in:
parent
37117407b0
commit
b55e1db153
4 changed files with 18 additions and 5 deletions
|
@ -20,6 +20,7 @@ import models
|
|||
from ox.django.api import actions
|
||||
from item import utils
|
||||
from item.models import Item
|
||||
from user.tasks import update_numberoflists
|
||||
|
||||
def get_list_or_404_json(id):
|
||||
id = id.split(':')
|
||||
|
@ -251,6 +252,7 @@ def addList(request):
|
|||
list.poster_frames = tuple(data['posterFrames'])
|
||||
|
||||
list.save()
|
||||
update_numberoflists.delay(request.user.username)
|
||||
|
||||
if 'items' in data:
|
||||
for item in Item.objects.filter(itemId__in=data['items']):
|
||||
|
@ -401,6 +403,7 @@ def removeList(request):
|
|||
response = json_response()
|
||||
if list.editable(request.user):
|
||||
list.delete()
|
||||
update_numberoflists.delay(request.user.username)
|
||||
else:
|
||||
response = json_response(status=403, text='not allowed')
|
||||
return render_to_json_response(response)
|
||||
|
|
|
@ -37,6 +37,8 @@ class SessionData(models.Model):
|
|||
system = models.CharField(default='', max_length=255)
|
||||
browser = models.CharField(default='', max_length=255)
|
||||
|
||||
numberoflists = models.IntegerField(default=0)
|
||||
|
||||
objects = managers.SessionDataManager()
|
||||
|
||||
groupssort = models.CharField(default=None,blank=True,null=True, max_length=255)
|
||||
|
@ -101,6 +103,7 @@ class SessionData(models.Model):
|
|||
self.level = self.user.get_profile().level
|
||||
self.firstseen = self.user.date_joined
|
||||
self.groupssort = ''.join([g.name for g in self.user.groups.all()])
|
||||
self.numberoflists = self.user.lists.count()
|
||||
else:
|
||||
self.level = 0
|
||||
self.groupssort = None
|
||||
|
@ -163,7 +166,7 @@ class SessionData(models.Model):
|
|||
j['level'] = p.get_level()
|
||||
j['newsletter'] = p.newsletter
|
||||
j['notes'] = p.notes
|
||||
j['numberoflists'] = self.user.lists.count()
|
||||
j['numberoflists'] = p.numberoflists
|
||||
if keys:
|
||||
for key in j.keys():
|
||||
if key not in keys:
|
||||
|
@ -294,7 +297,7 @@ def user_json(user, keys=None):
|
|||
'level': p.get_level(),
|
||||
'newsletter': p.newsletter,
|
||||
'notes': p.notes,
|
||||
'numberoflists': user.lists.count(),
|
||||
'numberoflists': p.numberoflists,
|
||||
'username': user.username,
|
||||
}
|
||||
if keys:
|
||||
|
|
|
@ -16,3 +16,12 @@ def parse_data(key):
|
|||
session_data = models.SessionData.objects.get(session_key=key)
|
||||
session_data.parse_data()
|
||||
session_data.save()
|
||||
|
||||
@task(ignore_resulsts=True, queue='default')
|
||||
def update_numberoflists(username):
|
||||
user = models.User.objects.get(username=username)
|
||||
models.SessionData.objects.filter(
|
||||
user=user
|
||||
).update(
|
||||
numberoflists=user.lists.count()
|
||||
)
|
||||
|
|
|
@ -442,11 +442,9 @@ def order_query(qs, sort):
|
|||
'timesseen': 'timesseen',
|
||||
'useragent': 'useragent',
|
||||
'username': 'username',
|
||||
'numberoflists': 'numberoflists',
|
||||
'windowsize': 'windowsize',
|
||||
}.get(e['key'], 'user__profile__%s'%e['key'])
|
||||
if key == 'user__profile__numberoflists':
|
||||
qs = qs.annotate(numberoflists=Sum('user__lists'))
|
||||
key = 'numberoflists'
|
||||
order = '%s%s' % (operator, key)
|
||||
order_by.append(order)
|
||||
if order_by:
|
||||
|
|
Loading…
Reference in a new issue