update timesaccessed sort value on access
This commit is contained in:
parent
b333f447f6
commit
ccfa48e3e0
3 changed files with 5 additions and 7 deletions
|
@ -1206,6 +1206,8 @@ class Access(models.Model):
|
|||
self.accessed = 0
|
||||
self.accessed += 1
|
||||
super(Access, self).save(*args, **kwargs)
|
||||
timesaccessed = Access.objects.filter(item=self.item).aggregate(Sum('accessed'))['accessed__sum']
|
||||
ItemSort.objects.filter(item=self.item).update(timesaccessed=timesaccessed)
|
||||
|
||||
def __unicode__(self):
|
||||
if self.user:
|
||||
|
|
|
@ -53,7 +53,6 @@ def _order_query(qs, sort, prefix='sort__'):
|
|||
key = {
|
||||
'id': 'itemId',
|
||||
'accessed': 'accessed__access',
|
||||
'viewed': 'accessed__access',
|
||||
}.get(e['key'], e['key'])
|
||||
if key not in ('accessed__access', 'accessed__accessed'):
|
||||
key = "%s%s" % (prefix, key)
|
||||
|
@ -237,13 +236,10 @@ Positions
|
|||
def only_p_sums(m):
|
||||
r = {}
|
||||
for p in _p:
|
||||
if p == 'viewed' and request.user.is_authenticated():
|
||||
value = m.accessed.filter(user=request.user).annotate(v=Max('access'))
|
||||
r[p] = value.exists() and value[0].v or None
|
||||
elif p == 'accessed':
|
||||
if p == 'accessed':
|
||||
r[p] = m.a
|
||||
elif p == 'timesaccessed':
|
||||
r[p] = m.sort.timesaccessed
|
||||
r[p] = m.timesaccessed
|
||||
else:
|
||||
r[p] = m.json.get(p, '')
|
||||
if 'clip_qs' in query:
|
||||
|
|
|
@ -690,7 +690,7 @@ def setUI(request):
|
|||
else:
|
||||
request.session['ui'] = json.dumps(ui)
|
||||
|
||||
if data.get('item', False):
|
||||
if data.get('item'):
|
||||
item = get_object_or_404_json(Item, itemId=data['item'])
|
||||
if request.user.is_authenticated():
|
||||
access, created = Access.objects.get_or_create(item=item, user=request.user)
|
||||
|
|
Loading…
Reference in a new issue