Added parent info to retrieved task nodes.
Added an Eve hook that adds {'parent_info: {'node_type': 'type', 'name': '...'}} to returned task nodes.
This commit is contained in:
@@ -78,9 +78,10 @@ class AttractExtension(PillarExtension):
|
|||||||
def setup_app(self, app):
|
def setup_app(self, app):
|
||||||
"""Connects Blinker signals."""
|
"""Connects Blinker signals."""
|
||||||
|
|
||||||
from . import subversion
|
from . import subversion, tasks
|
||||||
|
|
||||||
subversion.task_logged.connect(self.task_manager.task_logged_in_svn)
|
subversion.task_logged.connect(self.task_manager.task_logged_in_svn)
|
||||||
|
tasks.setup_app(app)
|
||||||
|
|
||||||
|
|
||||||
def _get_current_attract():
|
def _get_current_attract():
|
||||||
|
@@ -83,3 +83,9 @@ class TaskManager(object):
|
|||||||
|
|
||||||
task.update(api=api)
|
task.update(api=api)
|
||||||
return task
|
return task
|
||||||
|
|
||||||
|
|
||||||
|
def setup_app(app):
|
||||||
|
from . import eve_hooks
|
||||||
|
|
||||||
|
eve_hooks.setup_app(app)
|
||||||
|
45
attract/tasks/eve_hooks.py
Normal file
45
attract/tasks/eve_hooks.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
parent_id = node.get('parent')
|
||||||
|
if not parent_id:
|
||||||
|
return
|
||||||
|
|
||||||
|
nodes_coll = current_app.data.driver.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_tasks_parent_info(nodes):
|
||||||
|
for node in nodes['_items']:
|
||||||
|
fetch_task_parent_info(node)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_app(app):
|
||||||
|
app.on_fetched_item_nodes += fetch_task_parent_info
|
||||||
|
app.on_fetched_resource_nodes += fetch_tasks_parent_info
|
@@ -48,8 +48,6 @@ def view_embed_task(project, attract_props, task_id):
|
|||||||
users = project.get_users(api=api)
|
users = project.get_users(api=api)
|
||||||
project.users = users['_items']
|
project.users = users['_items']
|
||||||
|
|
||||||
log.info('Attract properties: %s', attract_props)
|
|
||||||
|
|
||||||
return render_template('attract/tasks/view_task_embed.html',
|
return render_template('attract/tasks/view_task_embed.html',
|
||||||
task=task,
|
task=task,
|
||||||
project=project,
|
project=project,
|
||||||
|
Reference in New Issue
Block a user