expand connections

This commit is contained in:
j 2011-09-30 19:37:41 +02:00
parent b4f1b59718
commit 9626995fd4
2 changed files with 22 additions and 1 deletions

View file

@ -256,6 +256,18 @@ class Item(models.Model):
self.external_data = data
self.save()
def expand_connections(self):
c = self.get('connections')
connections = {}
if c:
for t in c:
connections[t] = [{'item': l.itemId, 'title': l.get('title')}
for l in Item.objects.filter(itemId__in=c[t])]
connections[t].sort(key=lambda a: c[t].index(a['item']))
if not connections[t]:
del connections[t]
return connections
def __unicode__(self):
year = self.get('year')
if year:
@ -441,6 +453,9 @@ class Item(models.Model):
if 'cast' in i and isinstance(i['cast'][0], list):
i['cast'] = map(lambda x: {'actor': x[0], 'character': x[1]}, i['cast'])
if 'connections' in i:
i['connections'] = self.expand_connections()
if not keys or 'posterRatio' in keys:
i['posterRatio'] = self.poster_width / self.poster_height

View file

@ -304,7 +304,7 @@ pandora.ui.infoView = function(data) {
'Spoofs', 'Spoofed in'
].forEach(function(key) {
data.connections[key] && html.push(
formatKey(key) + formatValue(data.connections[key])
formatKey(key) + formatConnections(data.connections[key])
);
});
$div.html(html.join('; '));
@ -352,6 +352,12 @@ pandora.ui.infoView = function(data) {
return '<span style="color: rgb(128, 128, 128)">' + str + '</span>';
}
function formatConnections(connections) {
return connections.map(function(c) {
return '<a href="/' + c.item + '">' + c.title + '</a>';
}).join(', ');
}
function formatValue(value, key) {
return (Ox.isArray(value) ? value : [value]).map(function(value) {
return key ?