Added user-specific task list.

This commit is contained in:
2016-10-05 10:30:10 +02:00
parent 60c13615bf
commit 75e6b39069
7 changed files with 110 additions and 15 deletions

View File

@@ -7,8 +7,8 @@ from attract.node_types.task import node_type_task
log = logging.getLogger(__name__)
def fetch_task_parent_info(node):
"""Extends the node with some parent info.
def fetch_task_extra_info(node):
"""Extends the node with some info about its parent and project.
This allows us to link to the shot the task is attached to.
However, such a link requires at least knowing the parent node type,
@@ -18,11 +18,18 @@ def fetch_task_parent_info(node):
if node.get('node_type') != node_type_task['name']:
return
fetch_task_parent_info(node)
fetch_task_project_info(node)
def fetch_task_parent_info(node):
"""Store node parent info in node['_parent_info']."""
parent_id = node.get('parent')
if not parent_id:
return
nodes_coll = current_app.data.driver.db['nodes']
nodes_coll = current_app.db()['nodes']
parent = nodes_coll.find_one({'_id': parent_id},
projection={'node_type': 1,
'name': 1})
@@ -35,11 +42,32 @@ def fetch_task_parent_info(node):
node['_parent_info'] = parent
def fetch_task_project_info(node):
"""Store node project info in node['_project_info']."""
project_id = node.get('project')
if not project_id:
log.warning('Task node %s has no project!', node['_id'])
return
proj_coll = current_app.db()['projects']
project = proj_coll.find_one({'_id': project_id},
projection={'name': 1,
'url': 1})
if project is None:
log.warning("Task node %s has project %s, but the project doesn't exist.",
node['_id'], project_id)
return
project.pop('_id') # always there, but also already included in the node.
node['_project_info'] = project
def fetch_tasks_parent_info(nodes):
for node in nodes['_items']:
fetch_task_parent_info(node)
fetch_task_extra_info(node)
def setup_app(app):
app.on_fetched_item_nodes += fetch_task_parent_info
app.on_fetched_item_nodes += fetch_task_extra_info
app.on_fetched_resource_nodes += fetch_tasks_parent_info