def edit(data): ''' takes { id ... } setting identifier or base metadata is possible not both at the same time id can be one id or list of ids ''' response = {} ids = data['id'] if isinstance(ids, str): ids = [ids] edited = [] for id in ids: item = models.Item.get(id) if item and item.json()['mediastate'] == 'available': if 'primaryid' in data: if data['primaryid']: key, value = data['primaryid'] logger.debug('update primaryid %s %s', key, value) value = cleanup_id(key, value) item.update_primaryid(key, value) else: item.update_primaryid() response = item.json() else: item.edit_metadata(data) response = item.json() edited.append(id) else: logger.info('can only edit available items %s', id) if len(ids) > 1: response = data response['id'] = edited for key in list(state.cache): if key.startswith('group:'): state.cache.delete(key) state.user().clear_smart_list_cache() return response
def getMetadata(data): ''' takes { key: value includeEdits: boolean } key can be one of the supported identifiers: isbn10, isbn13, oclc, olid,... ''' logger.debug('getMetadata %s', data) if 'includeEdits' in data: include_edits = data.pop('includeEdits') else: include_edits = False key, value = next(iter(data.items())) value = cleanup_id(key, value) response = meta.lookup(key, value) if include_edits: response.update(models.Metadata.load(key, value)) if response: response['primaryid'] = [key, value] return response