get_type, no authors

This commit is contained in:
j 2014-05-21 13:07:41 +02:00
parent 2749f22703
commit e14c686dac
2 changed files with 22 additions and 3 deletions

View File

@ -72,7 +72,7 @@ def get_ids(key, value):
return ids
def lookup(id, return_all=False):
#print 'openlibrary.lookup', id
logger.debug('lookup %s', id)
info = api.get('/books/' + id).get('result', {})
#url = 'https://openlibrary.org/books/%s.json' % id
#info = json.loads(read_url(url))
@ -84,6 +84,12 @@ def lookup(id, return_all=False):
logger.debug('lookup %s => %s', id, data.keys())
return data
def get_type(obj):
type_ = obj.get('type')
if isinstance(type_, dict):
type_ = type_['key']
return type_
def format(info, return_all=False):
data = {}
if 'works' in info:
@ -96,7 +102,7 @@ def format(info, return_all=False):
if key == 'authors':
if work:
value = resolve_names([r['author']
for r in work['authors'] if r['type']['key'] == '/type/author_role'])
for r in work.get('authors', []) if get_type(r) == '/type/author_role'])
else:
value = resolve_names(value)
elif key == 'publish_country':

View File

@ -551,13 +551,26 @@ oml.ui.infoView = function(identifyData) {
.appendTo($div);
});
// -------- Primary ID
if (data.primaryid) {
$('<div>')
.css({
marginTop: '4px',
})
.html(
'<b>' + Ox.getObjectById(oml.config.itemKeys, data.primaryid[0]).title
+ ':</b> ' + data.primaryid[1]
)
.appendTo($info);
}
// -------- Classification
if (data.classification) {
$('<div>')
.css({
marginTop: '8px',
textAlign: 'justify'
})
.html(
formatValue(data.classification, 'classification')