forked from 0x2620/pandora
remove clip info from annotation table
This commit is contained in:
parent
78e29d254f
commit
a02d7f806b
2 changed files with 17 additions and 25 deletions
|
@ -91,12 +91,6 @@ class Annotation(models.Model):
|
||||||
layer = models.ForeignKey(Layer)
|
layer = models.ForeignKey(Layer)
|
||||||
value = models.TextField()
|
value = models.TextField()
|
||||||
|
|
||||||
duration = models.FloatField(default=0, db_index=True)
|
|
||||||
hue = models.FloatField(default=0, db_index=True)
|
|
||||||
saturation = models.FloatField(default=0, db_index=True)
|
|
||||||
lightness = models.FloatField(default=0, db_index=True)
|
|
||||||
volume = models.FloatField(default=0, db_index=True)
|
|
||||||
|
|
||||||
def editable(self, user):
|
def editable(self, user):
|
||||||
if user.is_authenticated():
|
if user.is_authenticated():
|
||||||
if user.is_staff or \
|
if user.is_staff or \
|
||||||
|
@ -111,15 +105,6 @@ class Annotation(models.Model):
|
||||||
else:
|
else:
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
def update_calculated_values(self):
|
|
||||||
self.duration = self.end - self.start
|
|
||||||
if self.duration > 0:
|
|
||||||
self.hue, self.saturation, self.lightness = extract.average_color(
|
|
||||||
self.item.timeline_prefix, self.start, self.end)
|
|
||||||
else:
|
|
||||||
self.hue = self.saturation = self.lightness = 0
|
|
||||||
#FIXME: set volume here
|
|
||||||
|
|
||||||
def set_public_id(self):
|
def set_public_id(self):
|
||||||
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count()
|
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count()
|
||||||
self.public_id = "%s/%s" % ( self.item.itemId, ox.to26(public_id))
|
self.public_id = "%s/%s" % ( self.item.itemId, ox.to26(public_id))
|
||||||
|
@ -128,20 +113,18 @@ class Annotation(models.Model):
|
||||||
if not self.id:
|
if not self.id:
|
||||||
super(Annotation, self).save(*args, **kwargs)
|
super(Annotation, self).save(*args, **kwargs)
|
||||||
self.set_public_id()
|
self.set_public_id()
|
||||||
if self.duration != self.end - self.start:
|
|
||||||
self.update_calculated_values()
|
#no clip or update clip
|
||||||
if not self.clip and not self.layer.private:
|
if not self.clip and not self.layer.private or \
|
||||||
|
(self.clip and not self.layer.private and \
|
||||||
|
self.start != self.clip.start or self.end != self.clip.end):
|
||||||
|
|
||||||
self.clip, created = Clip.objects.get_or_create(item=self.item,
|
self.clip, created = Clip.objects.get_or_create(item=self.item,
|
||||||
start=self.start,
|
start=self.start,
|
||||||
end=self.end)
|
end=self.end)
|
||||||
if created:
|
if created:
|
||||||
#FIXME, only clips should have those values
|
|
||||||
self.clip.duration = self.duration
|
|
||||||
self.clip.hue = self.hue
|
|
||||||
self.clip.saturation = self.saturation
|
|
||||||
self.clip.lightness = self.lightness
|
|
||||||
self.clip.volume = self.volume
|
|
||||||
self.clip.save()
|
self.clip.save()
|
||||||
|
|
||||||
super(Annotation, self).save(*args, **kwargs)
|
super(Annotation, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def json(self, layer=False, keys=None):
|
def json(self, layer=False, keys=None):
|
||||||
|
@ -151,9 +134,14 @@ class Annotation(models.Model):
|
||||||
for field in ('id', 'in', 'out', 'value', 'created', 'modified'):
|
for field in ('id', 'in', 'out', 'value', 'created', 'modified'):
|
||||||
|
|
||||||
j[field] = getattr(self, {
|
j[field] = getattr(self, {
|
||||||
|
'duration': 'clip__duration',
|
||||||
|
'hue': 'clip__hue',
|
||||||
'id': 'public_id',
|
'id': 'public_id',
|
||||||
'in': 'start',
|
'in': 'start',
|
||||||
|
'lightness': 'clip__lightness',
|
||||||
'out': 'end',
|
'out': 'end',
|
||||||
|
'saturation': 'clip__saturation',
|
||||||
|
'volume': 'clip__volume',
|
||||||
}.get(field, field))
|
}.get(field, field))
|
||||||
if layer:
|
if layer:
|
||||||
j['layer'] = self.layer.name
|
j['layer'] = self.layer.name
|
||||||
|
|
|
@ -46,12 +46,16 @@ def order_query(qs, sort):
|
||||||
if operator != '-':
|
if operator != '-':
|
||||||
operator = ''
|
operator = ''
|
||||||
key = {
|
key = {
|
||||||
|
'duration': 'clip__duration',
|
||||||
'in': 'start',
|
'in': 'start',
|
||||||
|
'lightness': 'clip__lightness',
|
||||||
'out': 'end',
|
'out': 'end',
|
||||||
|
'saturation': 'clip__saturation',
|
||||||
|
'volume': 'clip__volume',
|
||||||
}.get(e['key'], e['key'])
|
}.get(e['key'], e['key'])
|
||||||
if key.startswith('clip:'):
|
if key.startswith('clip:'):
|
||||||
key = annotation_sort_key(e['key'][len('clip:'):])
|
key = annotation_sort_key(e['key'][len('clip:'):])
|
||||||
elif key not in ('start', 'end', 'value'):
|
elif key not in ('start', 'end', 'value') and not key.startswith('clip__'):
|
||||||
#key mgith need to be changed, see order_sort in item/views.py
|
#key mgith need to be changed, see order_sort in item/views.py
|
||||||
key = "item__sort__%s" % key
|
key = "item__sort__%s" % key
|
||||||
order = '%s%s' % (operator, key)
|
order = '%s%s' % (operator, key)
|
||||||
|
|
Loading…
Reference in a new issue