annotation, oxdb_id

This commit is contained in:
j 2010-11-28 17:03:23 +01:00
parent 34b98ae985
commit da213d1745
8 changed files with 23 additions and 16 deletions

View file

@ -6,11 +6,11 @@ from django.contrib import admin
import models import models
class BinAdmin(admin.ModelAdmin):
search_fields = ['name', 'title']
admin.site.register(models.Bin, BinAdmin)
class LayerAdmin(admin.ModelAdmin): class LayerAdmin(admin.ModelAdmin):
search_fields = ['name', 'title'] search_fields = ['name', 'title']
admin.site.register(models.Layer, LayerAdmin) admin.site.register(models.Layer, LayerAdmin)
class AnnotationAdmin(admin.ModelAdmin):
search_fields = ['name', 'title']
admin.site.register(models.Annotation, AnnotationAdmin)

View file

@ -24,7 +24,7 @@ from ox import stripTags
from ox.normalize import canonicalTitle, canonicalName from ox.normalize import canonicalTitle, canonicalName
class Bin(models.Model): class Layer(models.Model):
class Meta: class Meta:
ordering = ('position', ) ordering = ('position', )
@ -42,7 +42,7 @@ class Bin(models.Model):
subtitle = models.BooleanField(default=True) #bis can be displayed as subtitle, only one bin subtitle = models.BooleanField(default=True) #bis can be displayed as subtitle, only one bin
find = models.BooleanField(default=True) find = models.BooleanField(default=True)
#words / item duration(wpm), total words, cuts per minute, cuts, number of layers, number of layers/duration #words / item duration(wpm), total words, cuts per minute, cuts, number of annotations, number of annotations/duration
sort = models.CharField(null=True, max_length=255) sort = models.CharField(null=True, max_length=255)
def properties(self): def properties(self):
@ -53,7 +53,10 @@ class Bin(models.Model):
print 'FIXME: need to add sort stuff' print 'FIXME: need to add sort stuff'
return p return p
class Layer(models.Model): def json(self):
return {'id': self.name, 'title': self.title, 'type': self.type}
class Annotation(models.Model):
#FIXME: here having a item,start index would be good #FIXME: here having a item,start index would be good
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)
@ -67,9 +70,6 @@ class Layer(models.Model):
type = models.CharField(blank=True, max_length=255) type = models.CharField(blank=True, max_length=255)
value = models.TextField() value = models.TextField()
#FIXME: relational layers, Locations, clips etc
#location = models.ForeignKey('Location', default=None)
def editable(self, user): def editable(self, user):
if user.is_authenticated(): if user.is_authenticated():
if obj.user == user.id or user.has_perm('0x.admin'): if obj.user == user.id or user.has_perm('0x.admin'):

View file

@ -30,7 +30,7 @@ import utils
import tasks import tasks
from archive import extract from archive import extract
from layer.models import Layer from annotaion.models import Annotation, Layer
from person.models import get_name_sort, Person from person.models import get_name_sort, Person
@ -47,6 +47,8 @@ def siteJson():
r['findKeys'].append(f) r['findKeys'].append(f)
r['groups'] = [p.name for p in Property.objects.filter(group=True)] r['groups'] = [p.name for p in Property.objects.filter(group=True)]
r['layers'] = [l.json() for l in Layer.objects()]
r['itemViews'] = [ r['itemViews'] = [
{"id": "info", "title": "Info"}, {"id": "info", "title": "Info"},
{"id": "statistics", "title": "Statistics"}, {"id": "statistics", "title": "Statistics"},
@ -286,7 +288,7 @@ class Item(models.Model):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.json = self.get_json() self.json = self.get_json()
if not self.oxdbId: if not self.oxdbId:
self.oxdbId = self.oxid() self.oxdbId = self.oxdb_id()
if self.poster: if self.poster:
self.poster_height = self.poster.height self.poster_height = self.poster.height
@ -412,7 +414,7 @@ class Item(models.Model):
layers['cuts'] = self.data.get('cuts', {}) layers['cuts'] = self.data.get('cuts', {})
layers['subtitles'] = {} layers['subtitles'] = {}
#FIXME: subtitles should be stored in Layer #FIXME: subtitles should be stored in Annotation
qs = self.files.filter(is_subtitle=True, is_main=True, available=True) qs = self.files.filter(is_subtitle=True, is_main=True, available=True)
if qs.count()>0: if qs.count()>0:
layers['subtitles'] = qs[0].srt() layers['subtitles'] = qs[0].srt()
@ -456,6 +458,10 @@ class Item(models.Model):
self.get('series title', ''), self.get('episode title', ''), self.get('series title', ''), self.get('episode title', ''),
self.get('season', ''), self.get('episode', '')) self.get('season', ''), self.get('episode', ''))
def oxdb_id(self):
return utils.oxdb_id(self.get('title', ''), self.get('directors', []), str(self.get('year', '')),
self.get('season', ''), self.get('episode', ''),
self.get('episode_title', ''), self.get('episode_directors', ''), self.get('episode_year', ''))
''' '''
Search related functions Search related functions
@ -490,7 +496,7 @@ class Item(models.Model):
#FIXME: #FIXME:
#f.dialog = 'fixme' #f.dialog = 'fixme'
save('dialog', '\n'.join([l.value for l in Layer.objects.filter(type='subtitle', item=self).order_by('start')])) save('dialog', '\n'.join([l.value for l in Annotation.objects.filter(type='subtitle', item=self).order_by('start')]))
#FIXME: collate filenames #FIXME: collate filenames
#f.filename = self.filename #f.filename = self.filename

View file

@ -30,11 +30,12 @@ def oxid(title, directors, year='', seriesTitle='', episodeTitle='', season=0, e
oxid += hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20] oxid += hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20]
return u"0x" + oxid return u"0x" + oxid
def oxdb_id(title, directors=[], year='', season='', episode='', episode_title='', episode_director='', episode_year=''): def oxdb_id(title, directors=[], year='', season='', episode='', episode_title='', episode_directors=[], episode_year=''):
# new id function, will replace oxid() # new id function, will replace oxid()
def get_hash(string): def get_hash(string):
return hashlib.sha1(string.encode('utf-8')).hexdigest().upper() return hashlib.sha1(string.encode('utf-8')).hexdigest().upper()
director = ', '.join(directors) director = ', '.join(directors)
episode_director = ', '.join(episode_directors)
if not episode: if not episode:
oxdb_id = get_hash(director)[:8] + get_hash('\n'.join([title, year]))[:8] oxdb_id = get_hash(director)[:8] + get_hash('\n'.join([title, year]))[:8]
else: else:

View file

@ -117,13 +117,13 @@ INSTALLED_APPS = (
# 'south', # 'south',
'djcelery', 'djcelery',
'annotaion',
'app', 'app',
'api', 'api',
'archive', 'archive',
'date', 'date',
'item', 'item',
'itemlist', 'itemlist',
'layer',
'person', 'person',
'place', 'place',
'text', 'text',