From a33c7f63257ffa56c0ee120cd1e14f1372648ba3 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 30 Sep 2011 16:09:30 +0200 Subject: [PATCH] move calculated values into function --- pandora/annotation/models.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index eb00e745..2d42f44c 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -108,18 +108,21 @@ class Annotation(models.Model): else: 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 save(self, *args, **kwargs): if not self.id: super(Annotation, self).save(*args, **kwargs) self.public_id = '%s/%s' % (self.item.itemId, ox.to32(self.id)) if self.duration != self.end - self.start: - 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 + self.update_calculated_values() super(Annotation, self).save(*args, **kwargs) def json(self, layer=False, keys=None):