dont save clip/sequence ids in db

This commit is contained in:
j 2012-06-18 16:36:04 +02:00
parent af8f7e2842
commit 81cef44d19
7 changed files with 47 additions and 37 deletions

View file

@ -23,7 +23,6 @@ def parseCondition(condition, user):
k = condition.get('key', 'name')
k = {
'event': 'annotations__events__id',
'id': 'public_id',
'in': 'start',
'out': 'end',
'place': 'annotations__places__id',
@ -53,14 +52,17 @@ def parseCondition(condition, user):
if op == '-':
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
& parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
if exclude:
return ~q
else:
return q
return exclude and ~q or q
if (not exclude and op == '=' or op in ('$', '^', '>=', '<')) and v == '':
return Q()
if k.endswith('__id'):
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])
return exclude and ~q or q
elif k.endswith('__id'):
v = decode_id(v)
if isinstance(v, bool): #featured and public flag
key = k

View file

@ -26,7 +26,6 @@ class MetaClip:
self.volume = 0
def save(self, *args, **kwargs):
self.public_id = u"%s/%0.03f-%0.03f" %(self.item.itemId, float(self.start), float(self.end))
if self.duration != self.end - self.start:
self.update_calculated_values()
if not self.aspect_ratio and self.item:
@ -89,10 +88,11 @@ class MetaClip:
def get_or_create(cls, item, start, end):
start = float(start)
end = float(end)
public_id = u"%s/%0.03f-%0.03f" %(item.itemId, start, end)
qs = cls.objects.filter(public_id=public_id)
start = float('%0.03f' % start)
end = float('%0.03f' % end)
qs = cls.objects.filter(item=item, start=start, end=end)
if qs.count() == 0:
clip = Clip(item=item, start=start, end=end, public_id=public_id)
clip = Clip(item=item, start=start, end=end)
clip.save()
created = True
else:
@ -100,6 +100,10 @@ class MetaClip:
created = False
return clip, created
@property
def public_id(self):
return u"%s/%0.03f-%0.03f" %(self.item.itemId, float(self.start), float(self.end))
def __unicode__(self):
return self.public_id
@ -112,7 +116,6 @@ attrs = {
'objects': managers.ClipManager(),
'created': models.DateTimeField(auto_now_add=True),
'modified': models.DateTimeField(auto_now=True),
'public_id': models.CharField(max_length=128, unique=True),
'aspect_ratio': models.FloatField(default=0),
'item': models.ForeignKey('item.Item', related_name='clips'),

View file

@ -60,8 +60,13 @@ def order_query(qs, sort):
elif key not in clip_keys:
#key mgith need to be changed, see order_sort in item/views.py
key = "sort__%s" % key
order = '%s%s' % (operator, key)
order_by.append(order)
if key == 'public_id':
order_by.append('%s%s' % (operator, 'sort__itemId'))
order_by.append('%s%s' % (operator, 'start'))
order_by.append('end')
else:
order = '%s%s' % (operator, key)
order_by.append(order)
if order_by:
qs = qs.order_by(*order_by, nulls_last=True)
return qs
@ -102,15 +107,19 @@ def findClips(request):
response['data']['items'] = [add(p) for p in qs]
keys = data['keys']
def clip_public_id(c):
return u'%s/%0.03f-%0.03f' % (c['public_id'].split('/')[0], c['clip__start'], c['clip__end'])
def add_annotations(key, qs, add_layer=False):
values = ['public_id', 'value', 'clip__public_id']
values = ['public_id', 'value', 'clip__start', 'clip__end']
if add_layer:
values.append('layer')
if query['filter']:
qs = qs.filter(query['filter'])
for a in qs.values(*values):
public_id = clip_public_id(a)
for i in response['data']['items']:
if i['id'] == a['clip__public_id']:
if i['id'] == public_id:
if not key in i:
i[key] = []
l = {
@ -130,7 +139,8 @@ def findClips(request):
add_annotations(layer, aqs)
elif 'position' in query:
qs = order_query(qs, query['sort'])
ids = [i['public_id'] for i in qs.values('public_id')]
ids = [u'%s/%0.03f-%0.03f' % (c['item__itemId'], c['start'], c['end'])
for c in qs.values('item__itemId', 'start', 'end')]
data['conditions'] = data['conditions'] + {
'value': data['position'],
'key': query['sort'][0]['key'],
@ -142,7 +152,8 @@ def findClips(request):
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
elif 'positions' in data:
qs = order_query(qs, query['sort'])
ids = [i['public_id'] for i in qs.values('public_id')]
ids = [u'%s/%0.03f-%0.03f' % (c['item__itemId'], c['start'], c['end'])
for c in qs.values('item__itemId', 'start', 'end')]
response['data']['positions'] = utils.get_positions(ids, data['positions'])
else:
response['data']['items'] = qs.count()

View file

@ -40,7 +40,7 @@ import archive.models
from person.models import get_name_sort
from title.models import get_title_sort
from sequence.tasks import get_sequences, update_sequence_ids
from sequence.tasks import get_sequences
def get_id(info):
q = Item.objects.all()
@ -367,9 +367,8 @@ class Item(models.Model):
for c in self.clips.all(): c.save()
for a in self.annotations.all():
public_id = a.public_id.split('/')[1]
a.public_id = "%s/%s" % ( self.itemId, public_id)
a.public_id = "%s/%s" % (self.itemId, public_id)
a.save()
update_sequence_ids.delay(self.itemId)
if update_poster:
return tasks.update_poster.delay(self.itemId)

View file

@ -22,7 +22,6 @@ def parseCondition(condition, user):
'''
k = condition.get('key', 'name')
k = {
'id': 'public_id',
'in': 'start',
'out': 'end'
}.get(k, k)
@ -41,13 +40,16 @@ def parseCondition(condition, user):
if op == '-':
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
& parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
if exclude:
return ~q
else:
return q
return exclude and ~q or q
if (not exclude and op == '=' or op in ('$', '^', '>=', '<')) and v == '':
return Q()
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])
return exclude and ~q or q
if k.endswith('__id'):
v = decode_id(v)
if isinstance(v, bool): #featured and public flag

View file

@ -19,10 +19,9 @@ from django.db import models
class Sequence(models.Model):
class Meta:
unique_together = ("public_id", "mode")
unique_together = ("item", "start", "end", "mode")
mode = models.CharField(max_length=128)
public_id = models.CharField(max_length=128)
item = models.ForeignKey(Item, null=True, related_name='sequences')
sort = models.ForeignKey(ItemSort, null=True, related_name='sequences')
user = models.IntegerField(db_index=True, null=True)
@ -35,15 +34,16 @@ class Sequence(models.Model):
objects = managers.SequenceManager()
def save(self, *args, **kwargs):
self.public_id = u"%s/%0.03f-%0.03f" % (
self.item.itemId, float(self.start), float(self.end)
)
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))
def __unicode__(self):
return self.public_id

View file

@ -33,9 +33,6 @@ def get_sequences(itemId):
'end': float('%0.03f' % s['out']),
'hash': s['hash']
}
sequence['public_id'] = u"%s/%0.03f-%0.03f" % (
i.itemId, sequence['start'], sequence['end']
)
sequence['duration'] = sequence['end'] - sequence['start']
if not keys:
keys = ', '.join(['"%s"'%k for k in sequence.keys()])
@ -48,7 +45,3 @@ def get_sequences(itemId):
cursor.execute(sql)
transaction.commit_unless_managed()
@task(ignore_results=True, queue='encoding')
def update_sequence_ids(itemId):
for s in models.Sequence.objects.filter(item__itemId=itemId):
s.save()