From b32ac91211b02d03fcb8e14c235797e8fce70616 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 1 Jun 2011 13:03:07 +0200 Subject: [PATCH] subtitles should annotations part 1 --- pandora/annotation/models.py | 7 +++++-- pandora/archive/models.py | 2 +- pandora/archive/tasks.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 0c0380b18..91ef7de36 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -101,8 +101,8 @@ class Annotation(models.Model): def get_id(self): return ox.to32(self.id) - def json(self): - return { + def json(self, layer=False): + j = { 'id': self.get_id(), 'user': self.user.username, 'in': self.start, @@ -111,6 +111,9 @@ class Annotation(models.Model): 'created': self.created, 'modified': self.modified } + if layer: + j['layer'] = self.layer.name + return j def __unicode__(self): return u"%s/%s-%s" %(self.item, self.start, self.end) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 386f5b4fa..e9c966184 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -19,7 +19,7 @@ import chardet from item import utils from item.models import Item from person.models import get_name_sort - +from annotation.models import Annotation, Layer class File(models.Model): created = models.DateTimeField(auto_now_add=True) diff --git a/pandora/archive/tasks.py b/pandora/archive/tasks.py index f6d20621b..6351665fa 100644 --- a/pandora/archive/tasks.py +++ b/pandora/archive/tasks.py @@ -88,3 +88,16 @@ def update_files(user, volume, files): #remove deleted files #FIXME: can this have any bad consequences? i.e. on the selction of used item files. models.Instance.objects.filter(volume=volume).exclude(file__oshash__in=all_files).delete() + +def import_subtitles(id): + f = models.File.objects.get(pk=id) + layer = models.Layer.objects.get(name='subtitles') + for data in f.srt(): + annotation = models.Annotation( + item=f.item, + layer=layer, + start=data['in'], + end=data['out'], + value=data['value'] + ) + annotation.save()