remove layer of indirection
This commit is contained in:
parent
7c37c1efde
commit
df9fc699ff
7 changed files with 17 additions and 81 deletions
|
@ -6,10 +6,6 @@ from django.contrib import admin
|
||||||
import models
|
import models
|
||||||
|
|
||||||
|
|
||||||
class LayerAdmin(admin.ModelAdmin):
|
|
||||||
search_fields = ['name', 'title']
|
|
||||||
admin.site.register(models.Layer, LayerAdmin)
|
|
||||||
|
|
||||||
class AnnotationAdmin(admin.ModelAdmin):
|
class AnnotationAdmin(admin.ModelAdmin):
|
||||||
search_fields = ['name', 'title']
|
search_fields = ['name', 'title']
|
||||||
admin.site.register(models.Annotation, AnnotationAdmin)
|
admin.site.register(models.Annotation, AnnotationAdmin)
|
||||||
|
|
|
@ -16,66 +16,6 @@ from tasks import update_matching_events, update_matching_places
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load_layers(layers):
|
|
||||||
for l in layers:
|
|
||||||
create_or_update_layer(l)
|
|
||||||
|
|
||||||
def create_or_update_layer(data):
|
|
||||||
layer, created = Layer.objects.get_or_create(name=data['id'])
|
|
||||||
for key in ('title', 'type', 'overlap', 'overlay', 'private'):
|
|
||||||
if key in data and getattr(layer, key) != data[key]:
|
|
||||||
setattr(layer, key, data[key])
|
|
||||||
created = True
|
|
||||||
if created:
|
|
||||||
layer.save()
|
|
||||||
return layer
|
|
||||||
|
|
||||||
class Layer(models.Model):
|
|
||||||
|
|
||||||
#class Meta:
|
|
||||||
# ordering = ('position', )
|
|
||||||
|
|
||||||
enabled = models.BooleanField(default=True)
|
|
||||||
|
|
||||||
name = models.CharField(null=True, max_length=255, unique=True)
|
|
||||||
title = models.CharField(null=True, max_length=255)
|
|
||||||
#text, string, string from list(fixme), date, place, person, pingback,
|
|
||||||
#What about: smart layers? for date, place, person
|
|
||||||
type = models.CharField(null=True, max_length=255)
|
|
||||||
|
|
||||||
#can this be changed per user?
|
|
||||||
position = models.IntegerField(default=0)
|
|
||||||
|
|
||||||
overlap = models.BooleanField(default=True)
|
|
||||||
overlay = models.BooleanField(default=True)
|
|
||||||
private = models.BooleanField(default=False) #false=users only see there own bins
|
|
||||||
|
|
||||||
#find/sort integration
|
|
||||||
find = models.BooleanField(default=True) #true part of find all
|
|
||||||
#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)
|
|
||||||
|
|
||||||
def properties(self):
|
|
||||||
p = {}
|
|
||||||
if self.find:
|
|
||||||
p[self.name] = {'type': 'bin', 'find': True}
|
|
||||||
if self.sort:
|
|
||||||
print 'FIXME: need to add sort stuff'
|
|
||||||
return p
|
|
||||||
|
|
||||||
def json(self):
|
|
||||||
return {
|
|
||||||
'id': self.name,
|
|
||||||
'overlap': self.overlap,
|
|
||||||
'private': self.private,
|
|
||||||
'title': self.title,
|
|
||||||
'type': self.type
|
|
||||||
}
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return self.title
|
|
||||||
|
|
||||||
|
|
||||||
class Annotation(models.Model):
|
class Annotation(models.Model):
|
||||||
objects = managers.AnnotationManager()
|
objects = managers.AnnotationManager()
|
||||||
|
|
||||||
|
@ -91,7 +31,7 @@ class Annotation(models.Model):
|
||||||
start = models.FloatField(default=-1, db_index=True)
|
start = models.FloatField(default=-1, db_index=True)
|
||||||
end = models.FloatField(default=-1)
|
end = models.FloatField(default=-1)
|
||||||
|
|
||||||
layer = models.ForeignKey(Layer)
|
layer = models.CharField(max_length=255, db_index=True)
|
||||||
value = models.TextField()
|
value = models.TextField()
|
||||||
|
|
||||||
def editable(self, user):
|
def editable(self, user):
|
||||||
|
|
|
@ -129,11 +129,10 @@ def addAnnotation(request):
|
||||||
return render_to_json_response(json_response(status=400,
|
return render_to_json_response(json_response(status=400,
|
||||||
text='invalid data'))
|
text='invalid data'))
|
||||||
|
|
||||||
#FIXME: this should be only called starting up server
|
|
||||||
models.load_layers(settings.CONFIG['layers'])
|
|
||||||
|
|
||||||
item = get_object_or_404_json(Item, itemId=data['item'])
|
item = get_object_or_404_json(Item, itemId=data['item'])
|
||||||
layer = get_object_or_404_json(models.Layer, name=data['layer'])
|
|
||||||
|
#FIXME: check that layer is a valid layer id
|
||||||
|
layer = data['layer']
|
||||||
|
|
||||||
annotation = models.Annotation(
|
annotation = models.Annotation(
|
||||||
item=item,
|
item=item,
|
||||||
|
|
|
@ -41,7 +41,7 @@ def parseCondition(condition, user):
|
||||||
return parseCondition({'key': 'annotations__value',
|
return parseCondition({'key': 'annotations__value',
|
||||||
'value': v,
|
'value': v,
|
||||||
'operator': op}, user) \
|
'operator': op}, user) \
|
||||||
& parseCondition({'key': 'annotations__layer__name',
|
& parseCondition({'key': 'annotations__layer',
|
||||||
'value': k,
|
'value': k,
|
||||||
'operator': '=='}, user)
|
'operator': '=='}, user)
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class MetaClip:
|
||||||
if streams:
|
if streams:
|
||||||
self.aspect_ratio = streams[0].aspect_ratio
|
self.aspect_ratio = streams[0].aspect_ratio
|
||||||
for l in self.layers:
|
for l in self.layers:
|
||||||
setattr(self, l, self.annotations.filter(layer__name=l).count()>0)
|
setattr(self, l, self.annotations.filter(layer=l).count()>0)
|
||||||
models.Model.save(self, *args, **kwargs)
|
models.Model.save(self, *args, **kwargs)
|
||||||
|
|
||||||
def json(self, keys=None):
|
def json(self, keys=None):
|
||||||
|
|
|
@ -105,10 +105,10 @@ def findClips(request):
|
||||||
if response['data']['items']:
|
if response['data']['items']:
|
||||||
if 'annotations' in keys:
|
if 'annotations' in keys:
|
||||||
add_annotations('annotations',
|
add_annotations('annotations',
|
||||||
Annotation.objects.filter(layer__name__in=models.Clip.layers, clip__in=ids))
|
Annotation.objects.filter(layer__in=models.Clip.layers, clip__in=ids))
|
||||||
for layer in filter(lambda l: l in keys, models.Clip.layers):
|
for layer in filter(lambda l: l in keys, models.Clip.layers):
|
||||||
add_annotations(layer,
|
add_annotations(layer,
|
||||||
Annotation.objects.filter(layer__name=layer, clip__in=ids))
|
Annotation.objects.filter(layer=layer, clip__in=ids))
|
||||||
elif 'position' in query:
|
elif 'position' in query:
|
||||||
qs = order_query(qs, query['sort'])
|
qs = order_query(qs, query['sort'])
|
||||||
ids = [i.public_id for i in qs]
|
ids = [i.public_id for i in qs]
|
||||||
|
|
|
@ -33,7 +33,7 @@ from .timelines import join_timelines
|
||||||
from data_api import external_data
|
from data_api import external_data
|
||||||
|
|
||||||
from archive import extract
|
from archive import extract
|
||||||
from annotation.models import Annotation, Layer
|
from annotation.models import Annotation
|
||||||
import archive.models
|
import archive.models
|
||||||
|
|
||||||
from person.models import get_name_sort
|
from person.models import get_name_sort
|
||||||
|
@ -414,12 +414,13 @@ class Item(models.Model):
|
||||||
|
|
||||||
def get_layers(self, user=None):
|
def get_layers(self, user=None):
|
||||||
layers = {}
|
layers = {}
|
||||||
for l in Layer.objects.all():
|
for l in settings.CONFIG['layers']:
|
||||||
ll = layers.setdefault(l.name, [])
|
name = l['id']
|
||||||
qs = Annotation.objects.filter(layer=l, item=self)
|
ll = layers.setdefault(name, [])
|
||||||
if l.name == 'subtitles':
|
qs = Annotation.objects.filter(layer=name, item=self)
|
||||||
|
if name == 'subtitles':
|
||||||
qs = qs.exclude(value='')
|
qs = qs.exclude(value='')
|
||||||
if l.private:
|
if l.get('private'):
|
||||||
if user and user.is_anonymous():
|
if user and user.is_anonymous():
|
||||||
user = None
|
user = None
|
||||||
qs = qs.filter(user=user)
|
qs = qs.filter(user=user)
|
||||||
|
@ -530,7 +531,7 @@ class Item(models.Model):
|
||||||
save(i,
|
save(i,
|
||||||
'\n'.join([f.path for f in self.files.all()]))
|
'\n'.join([f.path for f in self.files.all()]))
|
||||||
elif key['type'] == 'layer':
|
elif key['type'] == 'layer':
|
||||||
qs = Annotation.objects.filter(layer__name=i, item=self).order_by('start')
|
qs = Annotation.objects.filter(layer=i, item=self).order_by('start')
|
||||||
save(i, '\n'.join([l.value for l in qs]))
|
save(i, '\n'.join([l.value for l in qs]))
|
||||||
elif i != '*' and i not in self.facet_keys:
|
elif i != '*' and i not in self.facet_keys:
|
||||||
value = self.get(i)
|
value = self.get(i)
|
||||||
|
@ -1046,7 +1047,7 @@ class Item(models.Model):
|
||||||
|
|
||||||
def load_subtitles(self):
|
def load_subtitles(self):
|
||||||
with transaction.commit_on_success():
|
with transaction.commit_on_success():
|
||||||
layer = Layer.objects.get(name='subtitles')
|
layer = 'subtitles'
|
||||||
Annotation.objects.filter(layer=layer,item=self).delete()
|
Annotation.objects.filter(layer=layer,item=self).delete()
|
||||||
offset = 0
|
offset = 0
|
||||||
language = ''
|
language = ''
|
||||||
|
|
Loading…
Reference in a new issue