subtitles should annotations part 1

This commit is contained in:
j 2011-06-01 13:03:07 +02:00
parent e1ef4a33d8
commit f4e0aa7cf6
3 changed files with 19 additions and 3 deletions

View file

@ -101,8 +101,8 @@ class Annotation(models.Model):
def get_id(self): def get_id(self):
return ox.to32(self.id) return ox.to32(self.id)
def json(self): def json(self, layer=False):
return { j = {
'id': self.get_id(), 'id': self.get_id(),
'user': self.user.username, 'user': self.user.username,
'in': self.start, 'in': self.start,
@ -111,6 +111,9 @@ class Annotation(models.Model):
'created': self.created, 'created': self.created,
'modified': self.modified 'modified': self.modified
} }
if layer:
j['layer'] = self.layer.name
return j
def __unicode__(self): def __unicode__(self):
return u"%s/%s-%s" %(self.item, self.start, self.end) return u"%s/%s-%s" %(self.item, self.start, self.end)

View file

@ -19,7 +19,7 @@ import chardet
from item import utils from item import utils
from item.models import Item from item.models import Item
from person.models import get_name_sort from person.models import get_name_sort
from annotation.models import Annotation, Layer
class File(models.Model): class File(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)

View file

@ -88,3 +88,16 @@ def update_files(user, volume, files):
#remove deleted files #remove deleted files
#FIXME: can this have any bad consequences? i.e. on the selction of used item 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() 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()