update findMetadata
This commit is contained in:
parent
d88cb45727
commit
1405ccb6ca
2 changed files with 30 additions and 8 deletions
|
@ -217,7 +217,8 @@ actions.register(autocomplete)
|
|||
def findMetadata(data):
|
||||
'''
|
||||
takes {
|
||||
query: string,
|
||||
key: string,
|
||||
value: string
|
||||
}
|
||||
returns {
|
||||
items: [{
|
||||
|
@ -226,9 +227,34 @@ def findMetadata(data):
|
|||
}
|
||||
key is one of the supported identifiers: isbn10, isbn13...
|
||||
'''
|
||||
response = {}
|
||||
response = {
|
||||
'items': []
|
||||
}
|
||||
logger.debug('findMetadata %s', data)
|
||||
response['items'] = meta.find(data['query'])
|
||||
if data['key'] == 'isbn':
|
||||
r = meta.lookup(data['key'], data['value'])
|
||||
if r:
|
||||
response['items'].append(r)
|
||||
elif data['key'] == 'title':
|
||||
r = meta.find(data['value'])
|
||||
for isbn in meta.find(data['value']):
|
||||
r = meta.lookup('isbn', isbn)
|
||||
if r:
|
||||
response['items'].append(r)
|
||||
elif data['key'] == 'id':
|
||||
import user.models
|
||||
items = {}
|
||||
for m in user.models.Metadata.query.filter_by(item_id=data['value']):
|
||||
if m.data_hash not in items:
|
||||
items[m.data_hash] = m.data
|
||||
items[m.data_hash]['users'] = [m.user_id]
|
||||
j = items[m.data_hash]
|
||||
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
|
||||
if key in j and not isinstance(j[key], list):
|
||||
j[key] = [j[key]]
|
||||
else:
|
||||
items[m.data_hash]['users'].append(m.user_id)
|
||||
response['items'] = list(items.values())
|
||||
return response
|
||||
actions.register(findMetadata)
|
||||
|
||||
|
|
|
@ -22,11 +22,7 @@ def find(query):
|
|||
for isbn in isbns:
|
||||
if isbn not in done:
|
||||
isbn = stdnum.isbn.to_isbn13(isbn)
|
||||
r = {
|
||||
'isbn': [isbn],
|
||||
'primaryid': ['isbn', isbn]
|
||||
}
|
||||
results.append(r)
|
||||
results.append(isbn)
|
||||
done.add(isbn)
|
||||
if len(isbn) == 13 and isbn.startswith('978'):
|
||||
done.add(stdnum.isbn.to_isbn10(isbn))
|
||||
|
|
Loading…
Reference in a new issue