if references have title show them

This commit is contained in:
j 2011-09-30 20:13:56 +02:00
parent e5e82bf886
commit addd1780f1
2 changed files with 17 additions and 9 deletions

View file

@ -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')

View file

@ -354,7 +354,7 @@ pandora.ui.infoView = function(data) {
function formatConnections(connections) {
return connections.map(function(c) {
return '<a href="/' + c.item + '">' + c.title + '</a>';
return c.item ? '<a href="/' + c.item + '">' + c.title + '</a>' : c.title;
}).join(', ');
}