This commit is contained in:
rolux 2011-11-11 11:09:41 +00:00
commit 94757187fb
5 changed files with 11 additions and 9 deletions

View file

@ -3,6 +3,7 @@
import os import os
from os.path import join, dirname, basename, splitext, exists from os.path import join, dirname, basename, splitext, exists
import time
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.conf import settings from django.conf import settings
@ -20,11 +21,13 @@ class Command(BaseCommand):
def handle(self, **options): def handle(self, **options):
offset = 0 offset = 0
chunk = 100 chunk = 50
count = pos = models.Item.objects.count() count = pos = models.Item.objects.count()
while offset <= count: while offset <= count:
for i in models.Item.objects.all().order_by('id')[offset:offset+chunk]: for i in models.Item.objects.all().order_by('id')[offset:offset+chunk]:
print pos, i.itemId print pos, i.itemId
i.save() i.save()
time.sleep(1) #dont overload db
pos -= 1 pos -= 1
offset += chunk offset += chunk
time.sleep(30) #dont overload db

View file

@ -1206,6 +1206,8 @@ class Access(models.Model):
self.accessed = 0 self.accessed = 0
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']
ItemSort.objects.filter(item=self.item).update(timesaccessed=timesaccessed)
def __unicode__(self): def __unicode__(self):
if self.user: if self.user:

View file

@ -53,7 +53,6 @@ def _order_query(qs, sort, prefix='sort__'):
key = { key = {
'id': 'itemId', 'id': 'itemId',
'accessed': 'accessed__access', 'accessed': 'accessed__access',
'viewed': 'accessed__access',
}.get(e['key'], e['key']) }.get(e['key'], e['key'])
if key not in ('accessed__access', 'accessed__accessed'): if key not in ('accessed__access', 'accessed__accessed'):
key = "%s%s" % (prefix, key) key = "%s%s" % (prefix, key)
@ -237,13 +236,10 @@ Positions
def only_p_sums(m): def only_p_sums(m):
r = {} r = {}
for p in _p: for p in _p:
if p == 'viewed' and request.user.is_authenticated(): if p == 'accessed':
value = m.accessed.filter(user=request.user).annotate(v=Max('access'))
r[p] = value.exists() and value[0].v or None
elif p == 'accessed':
r[p] = m.a r[p] = m.a
elif p == 'timesaccessed': elif p == 'timesaccessed':
r[p] = m.sort.timesaccessed r[p] = m.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:

View file

@ -24,7 +24,8 @@ MANAGERS = ADMINS
# although not all choices may be available on all operating systems. # although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your # If running in a Windows environment this must be set to the same as your
# system time zone. # system time zone.
TIME_ZONE = 'Europe/Berlin' TIME_ZONE = 'UTC'
#TIME_ZONE = 'Asia/Kolkata' #TIME_ZONE = 'Asia/Kolkata'
# Language code for this installation. All choices can be found here: # Language code for this installation. All choices can be found here:

View file

@ -690,7 +690,7 @@ def setUI(request):
else: else:
request.session['ui'] = json.dumps(ui) 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']) item = get_object_or_404_json(Item, itemId=data['item'])
if request.user.is_authenticated(): if request.user.is_authenticated():
access, created = Access.objects.get_or_create(item=item, user=request.user) access, created = Access.objects.get_or_create(item=item, user=request.user)