forked from 0x2620/pandora
clips
This commit is contained in:
parent
fd116dbb70
commit
4884ae0503
2 changed files with 18 additions and 10 deletions
|
@ -118,13 +118,7 @@ class Annotation(models.Model):
|
||||||
if not self.clip and not self.layer.private or \
|
if not self.clip and not self.layer.private or \
|
||||||
(self.clip and not self.layer.private and \
|
(self.clip and not self.layer.private and \
|
||||||
self.start != self.clip.start or self.end != self.clip.end):
|
self.start != self.clip.start or self.end != self.clip.end):
|
||||||
|
self.clip, created = Clip.get_or_create(self.item, self.start, self.end)
|
||||||
self.clip, created = Clip.objects.get_or_create(item=self.item,
|
|
||||||
start=self.start,
|
|
||||||
end=self.end)
|
|
||||||
if created:
|
|
||||||
clip = Clip.objects.get(pk=self.clip.pk)
|
|
||||||
clip.save()
|
|
||||||
|
|
||||||
super(Annotation, self).save(*args, **kwargs)
|
super(Annotation, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ from django.conf import settings
|
||||||
from archive import extract
|
from archive import extract
|
||||||
import managers
|
import managers
|
||||||
|
|
||||||
|
|
||||||
class Clip(models.Model):
|
class Clip(models.Model):
|
||||||
'''
|
'''
|
||||||
CREATE INDEX clip_clip_title_idx ON clip_clip (title ASC NULLS LAST);
|
CREATE INDEX clip_clip_title_idx ON clip_clip (title ASC NULLS LAST);
|
||||||
|
@ -20,7 +21,7 @@ class Clip(models.Model):
|
||||||
|
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
public_id = models.CharField(max_length=128, unique=True, null=True)
|
public_id = models.CharField(max_length=128, unique=True)
|
||||||
|
|
||||||
item = models.ForeignKey('item.Item', related_name='clips')
|
item = models.ForeignKey('item.Item', related_name='clips')
|
||||||
|
|
||||||
|
@ -90,6 +91,19 @@ class Clip(models.Model):
|
||||||
j[key] = self.item.get(key)
|
j[key] = self.item.get(key)
|
||||||
return j
|
return j
|
||||||
|
|
||||||
def __unicode__(self):
|
@classmethod
|
||||||
return u"%s/%s-%s" %(self.item, self.start, self.end)
|
def get_or_create(cls, item, start, end):
|
||||||
|
public_id = u"%s/%s-%s" %(item.itemId, start, end)
|
||||||
|
qs = cls.objects.filter(public_id=public_id)
|
||||||
|
if qs.count() == 0:
|
||||||
|
clip = Clip(item=item, start=start, end=end, public_id=public_id)
|
||||||
|
clips.save()
|
||||||
|
created = True
|
||||||
|
else:
|
||||||
|
clip = qs[0]
|
||||||
|
created = False
|
||||||
|
return clip, created
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.public_id
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue