if references have title show them
This commit is contained in:
parent
e5e82bf886
commit
addd1780f1
2 changed files with 17 additions and 9 deletions
|
@ -258,15 +258,23 @@ class Item(models.Model):
|
||||||
|
|
||||||
def expand_connections(self):
|
def expand_connections(self):
|
||||||
c = self.get('connections')
|
c = self.get('connections')
|
||||||
connections = {}
|
|
||||||
if c:
|
if c:
|
||||||
for t in c:
|
for t in c.keys():
|
||||||
connections[t] = [{'item': l.itemId, 'title': l.get('title')}
|
if c[t]:
|
||||||
for l in Item.objects.filter(itemId__in=c[t])]
|
if isinstance(c[t][0], basestring):
|
||||||
connections[t].sort(key=lambda a: c[t].index(a['item']))
|
c[t]= [{'id': i, 'title': None} for i in c[t]]
|
||||||
if not connections[t]:
|
ids = [i['id'] for i in c[t]]
|
||||||
del connections[t]
|
known = {}
|
||||||
return connections
|
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):
|
def __unicode__(self):
|
||||||
year = self.get('year')
|
year = self.get('year')
|
||||||
|
|
|
@ -354,7 +354,7 @@ pandora.ui.infoView = function(data) {
|
||||||
|
|
||||||
function formatConnections(connections) {
|
function formatConnections(connections) {
|
||||||
return connections.map(function(c) {
|
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(', ');
|
}).join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue