Added editing of shots
This commit is contained in:
@@ -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
|
||||
|
@@ -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()
|
||||
|
@@ -1,6 +1,7 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
import responses
|
||||
from bson import ObjectId
|
||||
|
||||
import pillarsdk
|
||||
import pillar.tests
|
||||
@@ -82,3 +83,28 @@ class ShotManagerTest(AbstractAttractTest):
|
||||
u'effects': {task4['_id'], task5['_id']},
|
||||
None: {task6['_id']},
|
||||
}, shot_id_to_task[shot2_id])
|
||||
|
||||
@responses.activate
|
||||
def test_edit_shot(self):
|
||||
shot = self.create_shot()
|
||||
|
||||
with self.app.test_request_context():
|
||||
# Log in as project admin user
|
||||
pillar.auth.login_user(ctd.EXAMPLE_PROJECT_OWNER_ID)
|
||||
|
||||
self.mock_blenderid_validate_happy()
|
||||
|
||||
self.smngr.edit_shot(shot_id=shot['_id'],
|
||||
name=u'ผัดไทย',
|
||||
description=u'Shoot the Pad Thai',
|
||||
status='todo')
|
||||
|
||||
# Test directly with MongoDB
|
||||
with self.app.test_request_context():
|
||||
nodes_coll = self.app.data.driver.db['nodes']
|
||||
found = nodes_coll.find_one(ObjectId(shot['_id']))
|
||||
self.assertEqual(u'ผัดไทย', found['name'])
|
||||
self.assertEqual(u'todo', found['properties']['status'])
|
||||
self.assertEqual(u'Shoot the Pad Thai', found['description'])
|
||||
self.assertNotIn(u'notes', found['properties'])
|
||||
|
||||
|
@@ -62,7 +62,6 @@ class TaskWorkflowTest(AbstractAttractTest):
|
||||
name=u'nööw name',
|
||||
description=u'€ ≠ ¥',
|
||||
status='todo')
|
||||
self.assertIsNotNone(task)
|
||||
|
||||
# Test directly with MongoDB
|
||||
with self.app.test_request_context():
|
||||
|
Reference in New Issue
Block a user