add annotations to edits

This commit is contained in:
j 2014-01-22 18:24:21 +00:00
parent f39a90cfe3
commit 357e696f0d
2 changed files with 67 additions and 0 deletions

View file

@ -49,6 +49,13 @@ class Edit(models.Model):
def __unicode__(self): def __unicode__(self):
return u'%s (%s)' % (self.name, self.user) return u'%s (%s)' % (self.name, self.user)
@classmethod
def get(cls, id):
id = id.split(':')
username = id[0]
name = ":".join(id[1:])
return cls.objects.get(user__username=username, name=name)
def get_id(self): def get_id(self):
return u'%s:%s' % (self.user.username, self.name) return u'%s:%s' % (self.user.username, self.name)
@ -360,8 +367,35 @@ class Clip(models.Model):
data[key] = value data[key] = value
data['duration'] = data['out'] - data['in'] data['duration'] = data['out'] - data['in']
data['cuts'] = tuple([c for c in self.item.get('cuts') if c > self.start and c < self.end]) data['cuts'] = tuple([c for c in self.item.get('cuts') if c > self.start and c < self.end])
data['layers'] = self.get_layers(user)
return data return data
def get_layers(self, user=None):
if self.annotation:
start = self.annotation.start
end = self.annotation.end
item = self.annotation.item
else:
start = self.start
end = self.end
item = self.item
layers = {}
for l in settings.CONFIG['layers']:
name = l['id']
ll = layers.setdefault(name, [])
qs = Annotation.objects.filter(layer=name, item=item).order_by(
'start', 'end', 'sortvalue')
if name == 'subtitles':
qs = qs.exclude(value='')
qs = qs.filter(start__lt=end, end__gt=start)
if l.get('private'):
if user and user.is_anonymous():
user = None
qs = qs.filter(user=user)
for a in qs.order_by('start'):
ll.append(a.json(user=user))
return layers
class Position(models.Model): class Position(models.Model):
class Meta: class Meta:

View file

@ -78,6 +78,13 @@ pandora.ui.editPanel = function() {
function renderEdit() { function renderEdit() {
that = pandora.$ui.editPanel = Ox.VideoEditPanel({ that = pandora.$ui.editPanel = Ox.VideoEditPanel({
annotationsCalendarSize: ui.annotationsCalendarSize,
annotationsFont: ui.annotationsFont,
annotationsMapSize: ui.annotationsMapSize,
annotationsRange: ui.annotationsRange,
annotationsSize: ui.annotationsSize,
annotationsSort: ui.annotationsSort,
clickLink: pandora.clickLink,
clips: Ox.clone(edit.clips), clips: Ox.clone(edit.clips),
clipSize: listSize, clipSize: listSize,
clipSort: ui.edits[ui.edit].sort, clipSort: ui.edits[ui.edit].sort,
@ -97,6 +104,7 @@ pandora.ui.editPanel = function() {
}, },
height: pandora.$ui.appPanel.size(1), height: pandora.$ui.appPanel.size(1),
'in': ui.edits[ui.edit]['in'], 'in': ui.edits[ui.edit]['in'],
layers: getLayers(edit.clips),
loop: ui.videoLoop, loop: ui.videoLoop,
muted: ui.videoMuted, muted: ui.videoMuted,
out: ui.edits[ui.edit].out, out: ui.edits[ui.edit].out,
@ -104,8 +112,12 @@ pandora.ui.editPanel = function() {
resolution: ui.videoResolution, resolution: ui.videoResolution,
scaleToFill: ui.videoScale == 'fill', scaleToFill: ui.videoScale == 'fill',
selected: ui.edits[ui.edit].selection, selected: ui.edits[ui.edit].selection,
showAnnotationsCalendar: ui.showAnnotationsCalendar,
showAnnotationsMap: ui.showAnnotationsMap,
showClips: ui.showClips, showClips: ui.showClips,
showLayers: ui.showLayers,
showTimeline: ui.showTimeline, showTimeline: ui.showTimeline,
showUsers: pandora.site.annotations.showUsers,
smallTimelineURL: getSmallTimelineURL(), smallTimelineURL: getSmallTimelineURL(),
sort: ui.edits[ui.edit].sort, sort: ui.edits[ui.edit].sort,
sortOptions: [ sortOptions: [
@ -371,6 +383,26 @@ pandora.ui.editPanel = function() {
updateVideos(); updateVideos();
} }
function getLayers(clips) {
var layers = [];
pandora.site.layers.forEach(function(layer, i) {
layers[i] = Ox.extend({}, layer, {
title: Ox._(layer.title),
item: Ox._(layer.item),
items: Ox.flatten(clips.map(function(clip) {
return clip.layers[layer.id].map(function(annotation) {
var a = Ox.clone(annotation);
['in', 'out'].forEach(function(point) {
a[point] = a[point] - clip['in'] + clip['position'];
});
return a;
});
})),
});
});
return layers;
}
function serializeClips(clips) { function serializeClips(clips) {
// can be ids or clips // can be ids or clips
return clips.map(function(clip) { return clips.map(function(clip) {
@ -394,6 +426,7 @@ pandora.ui.editPanel = function() {
that.options({ that.options({
clips: Ox.clone(edit.clips), clips: Ox.clone(edit.clips),
duration: edit.duration, duration: edit.duration,
layers: getLayers(edit.clips),
smallTimelineURL: getSmallTimelineURL(), smallTimelineURL: getSmallTimelineURL(),
video: getVideos() video: getVideos()
}); });