Page MenuHome
No OneTemporary

File Metadata

Tue, Feb 18, 4:36 PM

import logging
from flask import current_app
from attract.node_types.task import node_type_task
log = logging.getLogger(__name__)
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,
which we thus embed here.
if node.get('node_type') != node_type_task['name']:
def fetch_task_parent_info(node):
"""Store node parent info in node['_parent_info']."""
parent_id = node.get('parent')
if not parent_id:
nodes_coll = current_app.db()['nodes']
parent = nodes_coll.find_one({'_id': parent_id},
projection={'node_type': 1,
'name': 1})
if parent is None:
log.warning("Task node %s has parent %s, but the parent doesn't exist.",
node['_id'], parent_id)
parent.pop('_id') # always there, but also already included in the 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'])
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)
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']:
def setup_app(app):
app.on_fetched_item_nodes += fetch_task_extra_info
app.on_fetched_resource_nodes += fetch_tasks_parent_info

Event Timeline