Added editing of shots

This commit is contained in:
2016-09-21 17:39:48 +02:00
parent 44540631e3
commit 0f95c01172
4 changed files with 63 additions and 1 deletions

View File

@@ -80,3 +80,28 @@ class ShotManager(object):
shot_id_to_tasks[task.parent][task_type].add(task)
return shot_id_to_tasks
def edit_shot(self, shot_id, **fields):
"""Edits a shot.
:type shot_id: str
:type fields: dict
:rtype: pillarsdk.Node
"""
api = pillar_api()
shot = pillarsdk.Node.find(shot_id, api=api)
shot.name = fields.pop('name')
shot.description = fields.pop('description')
shot.properties.status = fields.pop('status')
shot.properties.notes = fields.pop('notes', '').strip() or None
self._log.info('Saving shot %s', shot.to_dict())
if fields:
self._log.warning('edit_shot(%r, ...) called with unknown fields %r; ignoring them.',
shot_id, fields)
shot.update(api=api)
return shot

View File

@@ -72,6 +72,18 @@ def view_shot(project, attract_props, shot_id):
attract_props=attract_props)
@perproject_blueprint.route('/<shot_id>', methods=['POST'])
@attract_project_view()
def save(project, shot_id):
log.info('Saving shot %s', shot_id)
log.debug('Form data: %s', request.form)
shot_dict = request.form.to_dict()
shot = current_attract.shot_manager.edit_shot(shot_id, **shot_dict)
return flask.jsonify({'shot_id': shot_id, 'etag': shot._etag, 'time': shot._updated })
# TODO: remove GET method once Pablo has made a proper button to call this URL with a POST.
@perproject_blueprint.route('/create', methods=['POST', 'GET'])
@attract_project_view()