Page MenuHome

eve_hooks.py
No OneTemporary

File Metadata

Created
Thu, Feb 27, 10:13 AM

eve_hooks.py

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']:
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.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)
return
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'])
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_extra_info(node)
def setup_app(app):
app.on_fetched_item_nodes += fetch_task_extra_info
app.on_fetched_resource_nodes += fetch_tasks_parent_info

Event Timeline