forked from 0x2620/pandora
fix last accessed
This commit is contained in:
parent
05ac19b8b0
commit
eb61f62639
2 changed files with 7 additions and 10 deletions
|
@ -14,7 +14,7 @@ import unicodedata
|
||||||
from urllib import quote
|
from urllib import quote
|
||||||
|
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models import Count, Q, Sum
|
from django.db.models import Count, Q, Sum, Max
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
|
@ -605,6 +605,7 @@ class Item(models.Model):
|
||||||
'parts',
|
'parts',
|
||||||
'pixels',
|
'pixels',
|
||||||
'timesaccessed',
|
'timesaccessed',
|
||||||
|
'accessed',
|
||||||
'resolution',
|
'resolution',
|
||||||
'width',
|
'width',
|
||||||
'height',
|
'height',
|
||||||
|
@ -720,6 +721,7 @@ class Item(models.Model):
|
||||||
s.timesaccessed = self.accessed.aggregate(Sum('accessed'))['accessed__sum']
|
s.timesaccessed = self.accessed.aggregate(Sum('accessed'))['accessed__sum']
|
||||||
if not s.timesaccessed:
|
if not s.timesaccessed:
|
||||||
s.timesaccessed = 0
|
s.timesaccessed = 0
|
||||||
|
s.accessed = self.accessed.aggregate(Max('access'))['access__max']
|
||||||
s.save()
|
s.save()
|
||||||
#update cached values in clips
|
#update cached values in clips
|
||||||
self.clips.all().update(director=s.director, title=s.title)
|
self.clips.all().update(director=s.director, title=s.title)
|
||||||
|
@ -1208,7 +1210,7 @@ class Access(models.Model):
|
||||||
self.accessed += 1
|
self.accessed += 1
|
||||||
super(Access, self).save(*args, **kwargs)
|
super(Access, self).save(*args, **kwargs)
|
||||||
timesaccessed = Access.objects.filter(item=self.item).aggregate(Sum('accessed'))['accessed__sum']
|
timesaccessed = Access.objects.filter(item=self.item).aggregate(Sum('accessed'))['accessed__sum']
|
||||||
ItemSort.objects.filter(item=self.item).update(timesaccessed=timesaccessed)
|
ItemSort.objects.filter(item=self.item).update(timesaccessed=timesaccessed, accessed=self.access)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
if self.user:
|
if self.user:
|
||||||
|
|
|
@ -52,9 +52,8 @@ def _order_query(qs, sort, prefix='sort__'):
|
||||||
operator = ''
|
operator = ''
|
||||||
key = {
|
key = {
|
||||||
'id': 'itemId',
|
'id': 'itemId',
|
||||||
'accessed': 'accessed__access',
|
|
||||||
}.get(e['key'], e['key'])
|
}.get(e['key'], e['key'])
|
||||||
if key not in ('accessed__access', 'accessed__accessed'):
|
if key not in ('itemId', ):
|
||||||
key = "%s%s" % (prefix, key)
|
key = "%s%s" % (prefix, key)
|
||||||
order = '%s%s' % (operator, key)
|
order = '%s%s' % (operator, key)
|
||||||
order_by.append(order)
|
order_by.append(order)
|
||||||
|
@ -237,9 +236,9 @@ Positions
|
||||||
r = {}
|
r = {}
|
||||||
for p in _p:
|
for p in _p:
|
||||||
if p == 'accessed':
|
if p == 'accessed':
|
||||||
r[p] = m.a
|
r[p] = m.sort.accessed
|
||||||
elif p == 'timesaccessed':
|
elif p == 'timesaccessed':
|
||||||
r[p] = m.timesaccessed
|
r[p] = m.sort.timesaccessed
|
||||||
else:
|
else:
|
||||||
r[p] = m.json.get(p, '')
|
r[p] = m.json.get(p, '')
|
||||||
if 'clip_qs' in query:
|
if 'clip_qs' in query:
|
||||||
|
@ -256,10 +255,6 @@ Positions
|
||||||
return r
|
return r
|
||||||
qs = qs[query['range'][0]:query['range'][1]]
|
qs = qs[query['range'][0]:query['range'][1]]
|
||||||
#response['data']['items'] = [m.get_json(_p) for m in qs]
|
#response['data']['items'] = [m.get_json(_p) for m in qs]
|
||||||
if 'timesaccessed' in _p:
|
|
||||||
qs = qs.annotate(timesaccessed=Sum('accessed__accessed'))
|
|
||||||
if 'accessed' in _p:
|
|
||||||
qs = qs.annotate(a=Max('accessed__access'))
|
|
||||||
if 'viewed' in _p or 'timesaccessed' in _p or 'accessed' in _p:
|
if 'viewed' in _p or 'timesaccessed' in _p or 'accessed' in _p:
|
||||||
qs = qs.select_related()
|
qs = qs.select_related()
|
||||||
response['data']['items'] = [only_p_sums(m) for m in qs]
|
response['data']['items'] = [only_p_sums(m) for m in qs]
|
||||||
|
|
Loading…
Reference in a new issue