support all metadata keys in add (item)
This commit is contained in:
parent
4f14b923fa
commit
7ac8fefcf4
1 changed files with 47 additions and 36 deletions
|
@ -517,57 +517,8 @@ def get(request, data):
|
|||
return render_to_json_response(response)
|
||||
actions.register(get)
|
||||
|
||||
@login_required_json
|
||||
def add(request, data):
|
||||
'''
|
||||
Adds a new item (without video)
|
||||
takes {
|
||||
title: string, // title (optional)
|
||||
}
|
||||
returns {
|
||||
id: string, // item id
|
||||
title: string, // title
|
||||
... // more item properties
|
||||
}
|
||||
notes: To allow for this, set config option `itemRequiresVideo` to false.
|
||||
see: edit, find, get, lookup, remove, upload
|
||||
'''
|
||||
if not request.user.profile.capability('canAddItems'):
|
||||
response = json_response(status=403, text='permission denied')
|
||||
else:
|
||||
data['title'] = data.get('title', 'Untitled')
|
||||
i = models.Item()
|
||||
i.data['title'] = data['title']
|
||||
i.user = request.user
|
||||
p = i.save()
|
||||
if p:
|
||||
p.wait()
|
||||
else:
|
||||
i.make_poster()
|
||||
response = json_response(status=200, text='created')
|
||||
response['data'] = i.get_json()
|
||||
add_changelog(request, data, i.public_id)
|
||||
return render_to_json_response(response)
|
||||
actions.register(add, cache=False)
|
||||
|
||||
@login_required_json
|
||||
def edit(request, data):
|
||||
'''
|
||||
Edits metadata of an item
|
||||
takes {
|
||||
id: string, // item id
|
||||
key: value, // item key and new value
|
||||
... // more key/value pairs
|
||||
}
|
||||
returns {
|
||||
key: value // item key and new value
|
||||
... // more key/value pairs
|
||||
}
|
||||
see: add, find, get, lookup, remove, upload
|
||||
'''
|
||||
def edit_item(request, item, data):
|
||||
update_clips = False
|
||||
item = get_object_or_404_json(models.Item, public_id=data['id'])
|
||||
if item.editable(request.user):
|
||||
response = json_response(status=200, text='ok')
|
||||
if 'rightslevel' in data:
|
||||
if request.user.profile.capability('canEditRightsLevel'):
|
||||
|
@ -590,13 +541,73 @@ def edit(request, data):
|
|||
user_groups = set([g.name for g in request.user.groups.all()])
|
||||
other_groups = list(groups - user_groups)
|
||||
data['groups'] = [g for g in data['groups'] if g in user_groups] + other_groups
|
||||
add_changelog(request, data)
|
||||
r = item.edit(data)
|
||||
if r:
|
||||
r.wait()
|
||||
if update_clips:
|
||||
tasks.update_clips.delay(item.public_id)
|
||||
return response
|
||||
|
||||
@login_required_json
|
||||
def add(request, data):
|
||||
'''
|
||||
Adds a new item (without video)
|
||||
takes {
|
||||
title: string, // title (optional)
|
||||
|
||||
... // more key/value pairs (like edit, can be passed to add)
|
||||
}
|
||||
returns {
|
||||
id: string, // item id
|
||||
title: string, // title
|
||||
... // more item properties
|
||||
}
|
||||
notes: To allow for this, set config option `itemRequiresVideo` to false.
|
||||
see: edit, find, get, lookup, remove, upload
|
||||
'''
|
||||
if not request.user.profile.capability('canAddItems'):
|
||||
response = json_response(status=403, text='permission denied')
|
||||
else:
|
||||
response = json_response(status=200, text='created')
|
||||
data['title'] = data.get('title', 'Untitled')
|
||||
request_data = data.copy()
|
||||
item = models.Item()
|
||||
item.data['title'] = data['title']
|
||||
item.user = request.user
|
||||
p = item.save()
|
||||
if p:
|
||||
p.wait()
|
||||
else:
|
||||
i.make_poster()
|
||||
del data['title']
|
||||
if data:
|
||||
response = edit_item(request, item, data)
|
||||
response['data'] = item.get_json()
|
||||
add_changelog(request, request_data, item.public_id)
|
||||
return render_to_json_response(response)
|
||||
actions.register(add, cache=False)
|
||||
|
||||
@login_required_json
|
||||
def edit(request, data):
|
||||
'''
|
||||
Edits metadata of an item
|
||||
takes {
|
||||
id: string, // item id
|
||||
key: value, // item key and new value
|
||||
... // more key/value pairs
|
||||
}
|
||||
returns {
|
||||
key: value // item key and new value
|
||||
... // more key/value pairs
|
||||
}
|
||||
see: add, find, get, lookup, remove, upload
|
||||
'''
|
||||
item = get_object_or_404_json(models.Item, public_id=data['id'])
|
||||
if item.editable(request.user):
|
||||
request_data = data.copy()
|
||||
response = edit_item(request, item, data)
|
||||
response['data'] = item.get_json()
|
||||
add_changelog(request, request_data)
|
||||
else:
|
||||
response = json_response(status=403, text='permission denied')
|
||||
return render_to_json_response(response)
|
||||
|
|
Loading…
Reference in a new issue