clips next to map

This commit is contained in:
j 2011-06-20 17:02:53 +02:00
parent f26f717945
commit 8831c3d8dd
4 changed files with 94 additions and 4 deletions

View file

@ -20,6 +20,7 @@ def parseCondition(condition, user):
k = condition.get('key', 'name') k = condition.get('key', 'name')
k = { k = {
'user': 'user__username', 'user': 'user__username',
'place': 'places__id',
}.get(k, k) }.get(k, k)
if not k: if not k:
k = 'name' k = 'name'

View file

@ -43,6 +43,7 @@ class Place(models.Model):
matches = models.IntegerField(default=0) matches = models.IntegerField(default=0)
items = models.ManyToManyField(Item, blank=True, related_name='places') items = models.ManyToManyField(Item, blank=True, related_name='places')
annotations = models.ManyToManyField(Annotation, blank=True, related_name='places')
objects = managers.PlaceManager() objects = managers.PlaceManager()
@ -74,14 +75,18 @@ class Place(models.Model):
return j return j
def get_matches(self): def get_matches(self):
q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name) q = Q(value__contains=" " + self.name)|Q(value__startswith=self.name)
for name in self.alternativeNames: for name in self.alternativeNames:
q = q|Q(value__icontains=" " + name)|Q(value__startswith=name) q = q|Q(value__contains=" " + name)|Q(value__startswith=name)
return Annotation.objects.filter(q) return Annotation.objects.filter(q)
def update_matches(self): def update_matches(self):
matches = self.get_matches() matches = self.get_matches()
self.matches = matches.count() self.matches = matches.count()
for i in self.annotations.exclude(id__in=matches):
self.annotations.remove(i)
for i in matches.exclude(id__in=self.annotations.all()):
self.annotations.add(i)
ids = list(set([a.item.id for a in matches])) ids = list(set([a.item.id for a in matches]))
for i in self.items.exclude(id__in=ids): for i in self.items.exclude(id__in=ids):
self.items.remove(i) self.items.remove(i)

View file

@ -117,10 +117,54 @@ pandora.ui.item = function() {
showTypes: true, showTypes: true,
toolbar: true, toolbar: true,
width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE
}).bindEvent({
selectplace: function(event, place) {
if(place) {
pandora.$ui.clips.options({
items: function(data, callback) {
return pandora.api.findAnnotations($.extend(data, {
query: {
conditions:[{key: 'place', value: place.id, operator:'='}]
},
itemQuery: {conditions: [{
key: 'id',
value: pandora.user.ui.item,
operator: '='
}]}
}), callback);
}
});
} else {
pandora.$ui.clips.options({
items: []
});
}
}
}) })
}, },
{ {
element: Ox.Element(), element: pandora.$ui.clips = Ox.IconList({
item: function(data, sort, size) {
size = size || 128;
var ratio = data.aspectRatio,
width = size,
height = size/ratio,
url = '/' + data.item + '/frame/' + size + '/'+data['in'] + '.jpg';
return {
height: height,
id: data['id'],
info: Ox.formatDuration(data['in'], 'short') +' - '+ Ox.formatDuration(data['out'], 'short'),
title: data.value,
url: url,
width: width
};
},
items: [],
keys: ['id', 'value', 'in', 'out', 'aspectRatio', 'item'],
size: 128,
sort: pandora.user.ui.lists[pandora.user.ui.list].sort,
unique: 'id'
}),
id: 'place', id: 'place',
size: 144 + Ox.UI.SCROLLBAR_SIZE size: 144 + Ox.UI.SCROLLBAR_SIZE
} }

View file

@ -148,10 +148,50 @@ pandora.ui.list = function(view) { // fixme: remove view argument
showTypes: true, showTypes: true,
toolbar: true, toolbar: true,
width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE, width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE,
}).bindEvent({
selectplace: function(event, place) {
if(place) {
pandora.$ui.clips.options({
items: function(data, callback) {
return pandora.api.findAnnotations($.extend(data, {
query: {
conditions:[{key: 'place', value: place.id, operator:'='}]
},
itemQuery: pandora.Query.toObject()
}), callback);
}
});
} else {
pandora.$ui.clips.options({
items: []
});
}
}
}) })
}, },
{ {
element: Ox.Element(), element: pandora.$ui.clips = Ox.IconList({
item: function(data, sort, size) {
size = size || 128;
var ratio = data.aspectRatio,
width = size,
height = size/ratio,
url = '/' + data.item + '/frame/' + size + '/'+data['in'] + '.jpg';
return {
height: height,
id: data['id'],
info: Ox.formatDuration(data['in'], 'short') +' - '+ Ox.formatDuration(data['out'], 'short'),
title: data.value,
url: url,
width: width
};
},
items: [],
keys: ['id', 'value', 'in', 'out', 'aspectRatio', 'item'],
size: 128,
sort: pandora.user.ui.lists[pandora.user.ui.list].sort,
unique: 'id'
}),
id: 'place', id: 'place',
size: 144 + Ox.UI.SCROLLBAR_SIZE size: 144 + Ox.UI.SCROLLBAR_SIZE
} }