From 9626995fd449d7639640d6e9ad7e3ed92ca6fbbe Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 30 Sep 2011 19:37:41 +0200 Subject: [PATCH] expand connections --- pandora/item/models.py | 15 +++++++++++++++ static/js/pandora/ui/infoView.js | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 0b414fec..00111804 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -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 diff --git a/static/js/pandora/ui/infoView.js b/static/js/pandora/ui/infoView.js index 4b935d5c..b6f5f0cf 100644 --- a/static/js/pandora/ui/infoView.js +++ b/static/js/pandora/ui/infoView.js @@ -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 '' + str + ''; } + function formatConnections(connections) { + return connections.map(function(c) { + return '' + c.title + ''; + }).join(', '); + } + function formatValue(value, key) { return (Ox.isArray(value) ? value : [value]).map(function(value) { return key ?