From e14c686dace8964d92316b0b89759e8e37234679 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 21 May 2014 13:07:41 +0200 Subject: [PATCH] get_type, no authors --- oml/meta/openlibrary.py | 10 ++++++++-- static/js/infoView.js | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/oml/meta/openlibrary.py b/oml/meta/openlibrary.py index 8f583b1..d202881 100644 --- a/oml/meta/openlibrary.py +++ b/oml/meta/openlibrary.py @@ -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': diff --git a/static/js/infoView.js b/static/js/infoView.js index 4c2a241..4c1d5ac 100644 --- a/static/js/infoView.js +++ b/static/js/infoView.js @@ -551,13 +551,26 @@ oml.ui.infoView = function(identifyData) { .appendTo($div); }); + // -------- Primary ID + + if (data.primaryid) { + $('
') + .css({ + marginTop: '4px', + }) + .html( + '' + Ox.getObjectById(oml.config.itemKeys, data.primaryid[0]).title + + ': ' + data.primaryid[1] + ) + .appendTo($info); + } + // -------- Classification if (data.classification) { $('
') .css({ marginTop: '8px', - textAlign: 'justify' }) .html( formatValue(data.classification, 'classification')