optimize sequence table, save hash as bigint, mode as int, dont filter results by user
This commit is contained in:
parent
be5c89645c
commit
40eed92b7a
6 changed files with 385 additions and 41 deletions
|
@ -1,12 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from django.db.models import Q, Manager
|
||||
from django.conf import settings
|
||||
|
||||
from ox.django.query import QuerySet
|
||||
|
||||
from item.utils import decode_id
|
||||
|
||||
import models
|
||||
|
||||
|
||||
def parseCondition(condition, user):
|
||||
'''
|
||||
|
@ -47,13 +48,19 @@ def parseCondition(condition, user):
|
|||
if k == 'id':
|
||||
itemId, points = v.split('/')
|
||||
points = [float('%0.03f'%float(p)) for p in points.split('-')]
|
||||
q = Q(item__itemId=itemId, start=points[0], end=points[1])
|
||||
q = Q(sort__item__itemId=itemId, start=points[0], end=points[1])
|
||||
return exclude and ~q or q
|
||||
|
||||
if k == 'hash':
|
||||
v = models.parse_hash(v)
|
||||
if k == 'mode':
|
||||
v = models.Sequence.MODE[v]
|
||||
if k.endswith('__id'):
|
||||
v = decode_id(v)
|
||||
if isinstance(v, bool): #featured and public flag
|
||||
key = k
|
||||
else:
|
||||
if k in ('mode', 'hash'):
|
||||
key = k
|
||||
else:
|
||||
key = "%s%s" % (k, {
|
||||
'>': '__gt',
|
||||
|
@ -150,16 +157,4 @@ class SequenceManager(Manager):
|
|||
if conditions:
|
||||
qs = qs.filter(conditions)
|
||||
|
||||
#anonymous can only see public items
|
||||
if not user or user.is_anonymous():
|
||||
allowed_level = settings.CONFIG['capabilities']['canSeeItem']['guest']
|
||||
qs = qs.filter(sort__rightslevel__lte=allowed_level)
|
||||
#users can see public items, there own items and items of there groups
|
||||
else:
|
||||
allowed_level = settings.CONFIG['capabilities']['canSeeItem'][user.get_profile().get_level()]
|
||||
q = Q(sort__rightslevel__lte=allowed_level)|Q(user=user.id)
|
||||
if user.groups.count():
|
||||
q |= Q(item__groups__in=user.groups.all())
|
||||
qs = qs.filter(q)
|
||||
#admins can see all available items
|
||||
return qs
|
||||
|
|
187
pandora/sequence/migrations/0002_optimize1.py
Normal file
187
pandora/sequence/migrations/0002_optimize1.py
Normal file
|
@ -0,0 +1,187 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Removing unique constraint on 'Sequence', fields ['item', 'end', 'mode', 'start']
|
||||
db.delete_unique('sequence_sequence', ['item_id', 'end', 'mode', 'start'])
|
||||
|
||||
# Deleting field 'Sequence.item'
|
||||
db.delete_column('sequence_sequence', 'item_id')
|
||||
|
||||
# Deleting field 'Sequence.user'
|
||||
db.delete_column('sequence_sequence', 'user')
|
||||
|
||||
# Adding field 'Sequence.mode2'
|
||||
db.add_column('sequence_sequence', 'mode2',
|
||||
self.gf('django.db.models.fields.IntegerField')(default=0),
|
||||
keep_default=False)
|
||||
|
||||
# Adding field 'Sequence.hash2'
|
||||
db.add_column('sequence_sequence', 'hash2',
|
||||
self.gf('django.db.models.fields.BigIntegerField')(default=0, db_index=True),
|
||||
keep_default=False)
|
||||
|
||||
# Adding unique constraint on 'Sequence', fields ['sort', 'start', 'end', 'mode']
|
||||
db.create_unique('sequence_sequence', ['sort_id', 'start', 'end', 'mode'])
|
||||
|
||||
|
||||
for s in orm['sequence.Sequence'].objects.all():
|
||||
s.mode2 = s.mode == 'color' and 1 or 0
|
||||
s.hash2 = int(s.hash, 16) - 9223372036854775808
|
||||
s.save()
|
||||
|
||||
def backwards(self, orm):
|
||||
# Removing unique constraint on 'Sequence', fields ['sort', 'start', 'end', 'mode']
|
||||
db.delete_unique('sequence_sequence', ['sort_id', 'start', 'end', 'mode'])
|
||||
|
||||
# Adding field 'Sequence.item'
|
||||
db.add_column('sequence_sequence', 'item',
|
||||
self.gf('django.db.models.fields.related.ForeignKey')(related_name='sequences', null=True, to=orm['item.Item']),
|
||||
keep_default=False)
|
||||
|
||||
# Adding field 'Sequence.user'
|
||||
db.add_column('sequence_sequence', 'user',
|
||||
self.gf('django.db.models.fields.IntegerField')(null=True, db_index=True),
|
||||
keep_default=False)
|
||||
|
||||
# Deleting field 'Sequence.mode2'
|
||||
db.delete_column('sequence_sequence', 'mode2')
|
||||
|
||||
# Deleting field 'Sequence.hash2'
|
||||
db.delete_column('sequence_sequence', 'hash2')
|
||||
|
||||
# Adding unique constraint on 'Sequence', fields ['item', 'end', 'mode', 'start']
|
||||
db.create_unique('sequence_sequence', ['item_id', 'end', 'mode', 'start'])
|
||||
|
||||
|
||||
models = {
|
||||
'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
'auth.permission': {
|
||||
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
'auth.user': {
|
||||
'Meta': {'object_name': 'User'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
|
||||
},
|
||||
'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
'item.item': {
|
||||
'Meta': {'object_name': 'Item'},
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'data': ('ox.django.fields.DictField', [], {'default': '{}'}),
|
||||
'external_data': ('ox.django.fields.DictField', [], {'default': '{}'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'items'", 'blank': 'True', 'to': "orm['auth.Group']"}),
|
||||
'icon': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'itemId': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128', 'blank': 'True'}),
|
||||
'json': ('ox.django.fields.DictField', [], {'default': '{}'}),
|
||||
'level': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'notes': ('django.db.models.fields.TextField', [], {'default': "''"}),
|
||||
'oxdbId': ('django.db.models.fields.CharField', [], {'max_length': '42', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'poster': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'blank': 'True'}),
|
||||
'poster_frame': ('django.db.models.fields.FloatField', [], {'default': '-1'}),
|
||||
'poster_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||
'poster_source': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'poster_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||
'rendered': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
|
||||
'stream_aspect': ('django.db.models.fields.FloatField', [], {'default': '1.3333333333333333'}),
|
||||
'stream_info': ('ox.django.fields.DictField', [], {'default': '{}'}),
|
||||
'torrent': ('django.db.models.fields.files.FileField', [], {'default': 'None', 'max_length': '1000', 'blank': 'True'}),
|
||||
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'null': 'True', 'to': "orm['auth.User']"})
|
||||
},
|
||||
'item.itemsort': {
|
||||
'Meta': {'object_name': 'ItemSort'},
|
||||
'accessed': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'aspectratio': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'bitrate': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'cinematographer': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'codirector': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'color': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'composer': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'country': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'cutsperminute': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'director': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'duration': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'editor': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'genre': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'height': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'hue': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'imdbId': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'item': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'sort'", 'unique': 'True', 'primary_key': 'True', 'to': "orm['item.Item']"}),
|
||||
'itemId': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'language': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'lightness': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'lyricist': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'numberofactors': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'numberofcuts': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'numberoffiles': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'parts': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'pixels': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'producer': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'productionCompany': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'random': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'resolution': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'rightslevel': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'runtime': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'saturation': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'size': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'sound': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'timesaccessed': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'title': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'volume': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'width': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'words': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'wordsperminute': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'writer': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'year': ('django.db.models.fields.CharField', [], {'max_length': '4', 'null': 'True', 'db_index': 'True'})
|
||||
},
|
||||
'sequence.sequence': {
|
||||
'Meta': {'unique_together': "(('sort', 'start', 'end', 'mode'),)", 'object_name': 'Sequence'},
|
||||
'duration': ('django.db.models.fields.FloatField', [], {'default': '0'}),
|
||||
'end': ('django.db.models.fields.FloatField', [], {'default': '-1'}),
|
||||
'hash': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '16', 'db_index': 'True'}),
|
||||
'hash2': ('django.db.models.fields.BigIntegerField', [], {'default': '0', 'db_index': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'mode': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'mode2': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||
'sort': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sequences'", 'null': 'True', 'to': "orm['item.ItemSort']"}),
|
||||
'start': ('django.db.models.fields.FloatField', [], {'default': '-1', 'db_index': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['sequence']
|
158
pandora/sequence/migrations/0003_optimize2.py
Normal file
158
pandora/sequence/migrations/0003_optimize2.py
Normal file
|
@ -0,0 +1,158 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Deleting field 'Sequence.hash2'
|
||||
db.delete_column('sequence_sequence', 'hash')
|
||||
|
||||
# Deleting field 'Sequence.mode2'
|
||||
db.delete_column('sequence_sequence', 'mode')
|
||||
|
||||
db.rename_column('sequence_sequence', 'hash2', 'hash')
|
||||
db.rename_column('sequence_sequence', 'mode2', 'mode')
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
db.rename_column('sequence_sequence', 'hash', 'hash2')
|
||||
db.rename_column('sequence_sequence', 'mode', 'mode2')
|
||||
|
||||
# Adding field 'Sequence.hash'
|
||||
db.add_column('sequence_sequence', 'hash',
|
||||
self.gf('django.db.models.fields.CharField')(max_length=16),
|
||||
keep_default=False)
|
||||
|
||||
# Adding field 'Sequence.mode'
|
||||
db.add_column('sequence_sequence', 'mode',
|
||||
self.gf('django.db.models.fields.CharField')(max_length=128),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
models = {
|
||||
'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
'auth.permission': {
|
||||
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
'auth.user': {
|
||||
'Meta': {'object_name': 'User'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
|
||||
},
|
||||
'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
'item.item': {
|
||||
'Meta': {'object_name': 'Item'},
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'data': ('ox.django.fields.DictField', [], {'default': '{}'}),
|
||||
'external_data': ('ox.django.fields.DictField', [], {'default': '{}'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'items'", 'blank': 'True', 'to': "orm['auth.Group']"}),
|
||||
'icon': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'itemId': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128', 'blank': 'True'}),
|
||||
'json': ('ox.django.fields.DictField', [], {'default': '{}'}),
|
||||
'level': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'notes': ('django.db.models.fields.TextField', [], {'default': "''"}),
|
||||
'oxdbId': ('django.db.models.fields.CharField', [], {'max_length': '42', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'poster': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'blank': 'True'}),
|
||||
'poster_frame': ('django.db.models.fields.FloatField', [], {'default': '-1'}),
|
||||
'poster_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||
'poster_source': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'poster_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||
'rendered': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
|
||||
'stream_aspect': ('django.db.models.fields.FloatField', [], {'default': '1.3333333333333333'}),
|
||||
'stream_info': ('ox.django.fields.DictField', [], {'default': '{}'}),
|
||||
'torrent': ('django.db.models.fields.files.FileField', [], {'default': 'None', 'max_length': '1000', 'blank': 'True'}),
|
||||
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'null': 'True', 'to': "orm['auth.User']"})
|
||||
},
|
||||
'item.itemsort': {
|
||||
'Meta': {'object_name': 'ItemSort'},
|
||||
'accessed': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'aspectratio': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'bitrate': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'cinematographer': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'codirector': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'color': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'composer': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'country': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'cutsperminute': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'director': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'duration': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'editor': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'genre': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'height': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'hue': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'imdbId': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'item': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'sort'", 'unique': 'True', 'primary_key': 'True', 'to': "orm['item.Item']"}),
|
||||
'itemId': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'language': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'lightness': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'lyricist': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'numberofactors': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'numberofcuts': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'numberoffiles': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'parts': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'pixels': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'producer': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'productionCompany': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'random': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'resolution': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'rightslevel': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'runtime': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'saturation': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'size': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'sound': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'timesaccessed': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'title': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'volume': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'width': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'words': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'wordsperminute': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
|
||||
'writer': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}),
|
||||
'year': ('django.db.models.fields.CharField', [], {'max_length': '4', 'null': 'True', 'db_index': 'True'})
|
||||
},
|
||||
'sequence.sequence': {
|
||||
'Meta': {'unique_together': "(('sort', 'start', 'end', 'mode'),)", 'object_name': 'Sequence'},
|
||||
'duration': ('django.db.models.fields.FloatField', [], {'default': '0'}),
|
||||
'end': ('django.db.models.fields.FloatField', [], {'default': '-1'}),
|
||||
'hash': ('django.db.models.fields.BigIntegerField', [], {'default': '-9223372036854775808', 'db_index': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'mode': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||
'sort': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sequences'", 'null': 'True', 'to': "orm['item.ItemSort']"}),
|
||||
'start': ('django.db.models.fields.FloatField', [], {'default': '-1', 'db_index': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['sequence']
|
|
@ -5,19 +5,27 @@ from __future__ import division, with_statement
|
|||
from django.db import models
|
||||
|
||||
import managers
|
||||
from item.models import Item, ItemSort
|
||||
from item.models import ItemSort
|
||||
|
||||
|
||||
def parse_hash(value):
|
||||
return int(value, 16) - 9223372036854775808
|
||||
|
||||
def format_hash(value):
|
||||
return hex(value + 9223372036854775808)[2:-1].upper()
|
||||
|
||||
class Sequence(models.Model):
|
||||
class Meta:
|
||||
unique_together = ("item", "start", "end", "mode")
|
||||
unique_together = ("sort", "start", "end", "mode")
|
||||
|
||||
mode = models.CharField(max_length=128)
|
||||
item = models.ForeignKey(Item, null=True, related_name='sequences')
|
||||
MODE = {
|
||||
'shape': 0,
|
||||
'color': 1
|
||||
}
|
||||
mode = models.IntegerField(choices=sorted(zip(MODE.values(), MODE.keys()), key=lambda k: k[0]), default=0)
|
||||
sort = models.ForeignKey(ItemSort, null=True, related_name='sequences')
|
||||
user = models.IntegerField(db_index=True, null=True)
|
||||
|
||||
hash = models.CharField(db_index=True, max_length=16, default='')
|
||||
hash = models.BigIntegerField(db_index=True, default=-9223372036854775808)
|
||||
start = models.FloatField(default=-1, db_index=True)
|
||||
end = models.FloatField(default=-1)
|
||||
duration = models.FloatField(default=0)
|
||||
|
@ -26,14 +34,11 @@ class Sequence(models.Model):
|
|||
|
||||
def save(self, *args, **kwargs):
|
||||
self.duration = self.end - self.start
|
||||
if self.item:
|
||||
self.user = self.item.user and self.item.user.id
|
||||
self.sort = self.item.sort
|
||||
super(Sequence, self).save(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def public_id(self):
|
||||
return u"%s/%0.03f-%0.03f" % (self.item.itemId, float(self.start), float(self.end))
|
||||
return u"%s/%0.03f-%0.03f" % (self.sort.item.itemId, float(self.start), float(self.end))
|
||||
|
||||
def __unicode__(self):
|
||||
return self.public_id
|
||||
|
@ -41,12 +46,12 @@ class Sequence(models.Model):
|
|||
def json(self, keys=None, user=None):
|
||||
j = {
|
||||
'id': self.public_id,
|
||||
'hash': self.hash,
|
||||
'hash': format_hash(self.hash),
|
||||
'in': float('%0.03f' % self.start),
|
||||
'out': float('%0.03f' % self.end),
|
||||
}
|
||||
if keys:
|
||||
for key in keys:
|
||||
if key not in j:
|
||||
j[key] = self.item.json.get(key)
|
||||
j[key] = self.sort.item.json.get(key)
|
||||
return j
|
||||
|
|
|
@ -18,12 +18,11 @@ def get_sequences(itemId):
|
|||
for mode in data:
|
||||
for s in data[mode]:
|
||||
sequence = {
|
||||
'item_id': i.pk,
|
||||
'sort_id': i.sort.pk,
|
||||
'mode': mode,
|
||||
'start': float('%0.03f' % s['in']),
|
||||
'end': float('%0.03f' % s['out']),
|
||||
'hash': s['hash']
|
||||
'hash': models.parse_hash(s['hash'])
|
||||
}
|
||||
sequence['duration'] = sequence['end'] - sequence['start']
|
||||
if not keys:
|
||||
|
|
|
@ -110,8 +110,8 @@ def getSequence(request):
|
|||
response = json_response()
|
||||
position = float('%0.03f' % data['position'])
|
||||
qs = models.Sequence.objects.filter(
|
||||
item__itemId=data['id'],
|
||||
mode=data['mode'],
|
||||
sort__item__itemId=data['id'],
|
||||
mode=models.Sequence.MODE[data['mode']],
|
||||
start__lte=position,
|
||||
end__gt=position
|
||||
).order_by('start', 'end')
|
||||
|
|
Loading…
Reference in a new issue