From addd1780f14ced8f50c2794f9b9434d6c9256549 Mon Sep 17 00:00:00 2001
From: j <0x006A@0x2620.org>
Date: Fri, 30 Sep 2011 20:13:56 +0200
Subject: [PATCH] if references have title show them
---
pandora/item/models.py | 24 ++++++++++++++++--------
static/js/pandora/ui/infoView.js | 2 +-
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/pandora/item/models.py b/pandora/item/models.py
index 00111804..7e00d403 100644
--- a/pandora/item/models.py
+++ b/pandora/item/models.py
@@ -258,15 +258,23 @@ class Item(models.Model):
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
+ for t in c.keys():
+ if c[t]:
+ if isinstance(c[t][0], basestring):
+ c[t]= [{'id': i, 'title': None} for i in c[t]]
+ ids = [i['id'] for i in c[t]]
+ known = {}
+ for l in Item.objects.filter(itemId__in=ids):
+ known[l.itemId] = l.get('title')
+ for i in c[t]:
+ if i['id'] in known:
+ i['item'] = i['id']
+ i['title'] = known[i['id']]
+ c[t]= filter(lambda x: x['title'], c[t])
+ if not c[t]:
+ del c[t]
+ return c
def __unicode__(self):
year = self.get('year')
diff --git a/static/js/pandora/ui/infoView.js b/static/js/pandora/ui/infoView.js
index b6f5f0cf..6d754077 100644
--- a/static/js/pandora/ui/infoView.js
+++ b/static/js/pandora/ui/infoView.js
@@ -354,7 +354,7 @@ pandora.ui.infoView = function(data) {
function formatConnections(connections) {
return connections.map(function(c) {
- return '' + c.title + '';
+ return c.item ? '' + c.title + '' : c.title;
}).join(', ');
}