support batch edit

This commit is contained in:
j 2016-01-05 14:01:38 +05:30
parent 9aff4766e5
commit cd6d09c86c
1 changed files with 20 additions and 14 deletions

View File

@ -121,24 +121,30 @@ def edit(data):
... ...
} }
setting identifier or base metadata is possible not both at the same time setting identifier or base metadata is possible not both at the same time
id can be one id or list of ids
''' '''
response = {} response = {}
item = models.Item.get(data['id']) ids = data['id']
if item and item.json()['mediastate'] == 'available': if isinstance(ids, str):
if 'primaryid' in data: ids = [ids]
if data['primaryid']: for id in ids:
key, value = data['primaryid'] item = models.Item.get(id)
logger.debug('update primaryid %s %s', key, value) if item and item.json()['mediastate'] == 'available':
value = cleanup_id(key, value) if 'primaryid' in data:
item.update_primaryid(key, value) 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: else:
item.update_primaryid() item.edit_metadata(data)
response = item.json() response = item.json()
else: else:
item.edit_metadata(data) logger.info('can only edit available items %s', id)
response = item.json()
else:
logger.info('can only edit available items')
return response return response
actions.register(edit, cache=False) actions.register(edit, cache=False)