diff --git a/pandora/item/management/__init__.py b/pandora/item/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pandora/item/management/commands/__init__.py b/pandora/item/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pandora/item/management/commands/rebuildcache.py b/pandora/item/management/commands/rebuildcache.py new file mode 100644 index 00000000..a3f2417f --- /dev/null +++ b/pandora/item/management/commands/rebuildcache.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 + +import os +from os.path import join, dirname, basename, splitext, exists + +from django.core.management.base import BaseCommand, CommandError +from django.conf import settings + +from ... import models + + +class Command(BaseCommand): + """ + rebuild sort/search cache for all items. + """ + help = 'listen to rabbitmq and execute encoding tasks.' + args = '' + + def handle(self, **options): + offset = 0 + chunk = 100 + pos = models.Item.objects.count() + while offset <= models.Item.objects.count(): + for i in models.Item.objects.all().order_by('id')[offset:offset+chunk]: + print pos, i.itemId + i.save() + pos -= 1 + offset += chunk diff --git a/pandora/item/models.py b/pandora/item/models.py index 2b7f9079..4b350efd 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -164,7 +164,6 @@ class Item(models.Model): return '/%s' % self.itemId def save(self, *args, **kwargs): - self.json = self.get_json() self.oxdbId = self.oxdb_id() if self.poster: @@ -173,10 +172,11 @@ class Item(models.Model): else: self.poster_height = 128 self.poster_width = 80 - super(Item, self).save(*args, **kwargs) self.update_find() self.update_sort() self.update_facets() + self.json = self.get_json() + super(Item, self).save(*args, **kwargs) def delete(self, *args, **kwargs): self.delete_poster() @@ -298,7 +298,9 @@ class Item(models.Model): return layers def get_json(self, fields=None): - item = {} + item = { + 'id': self.itemId + } item.update(self.external_data) item.update(self.data) for key in site_config['keys'].keys(): @@ -490,10 +492,10 @@ class Item(models.Model): value = self.get(source, None) if isinstance(value, basestring): value = datetime.strptime(value, '%Y-%m-%d') - setattr(s, '%s_desc'%name, value) + setattr(s, name, value) if not value: value = datetime.strptime('9999-12-12', '%Y-%m-%d') - setattr(s, name, value) + setattr(s, '%s_desc'%name, value) #sort keys based on database, these will always be available s.itemId = self.itemId.replace('0x', 'xx') diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index 0320c578..28c7fc82 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -5,6 +5,7 @@ from __future__ import division, with_statement from django.db import models from django.contrib.auth.models import User +from ox.django.fields import DictField class List(models.Model): @@ -16,6 +17,9 @@ class List(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=255) public = models.BooleanField(default=False) + + query = DictField(default={}) + items = models.ManyToManyField('item.Item', related_name='lists', through='ListItem') diff --git a/pandora/templates/site.json b/pandora/templates/site.json index 14b04f78..269771d1 100644 --- a/pandora/templates/site.json +++ b/pandora/templates/site.json @@ -83,7 +83,7 @@ {"id": "producer", "title": "Producer", "width": 180, "type": "person"}, {"id": "cinematographer", "title": "Cinematographer", "width": 180, "type": "person"}, {"id": "editor", "title": "Editor", "width": 180, "type": "person"}, - {"id": "actor", "title": "Number of Actors", "width": 60, "type": "person"}, + {"id": "numberofactors", "title": "Number of Actors", "width": 60, "key": "actor", "type": "length"}, {"id": "genre", "title": "Genre", "width": 120, "type": "string"}, {"id": "numberofkeywords", "title": "Number of Keywords", "width": 60, "key": "keyword", "type": "length"}, {"id": "wordsinsummary", "title": "Words in Summary", "width": 60, "key": "summary", "type": "words"},