Added shot overview with tasks.

javascript links to open or create tasks aren't implemented yet.
This commit is contained in:
2016-09-21 16:35:52 +02:00
parent 4b1a52f26e
commit d97d1183a5
6 changed files with 166 additions and 11 deletions

View File

@@ -1,5 +1,7 @@
"""Shot management."""
import collections
import attr
import flask_login
@@ -8,6 +10,7 @@ from pillar.web.system_util import pillar_api
from . import attrs_extra
from .node_types.shot import node_type_shot
from .node_types.task import node_type_task
@attr.s
@@ -38,3 +41,42 @@ class ShotManager(object):
shot = pillarsdk.Node(node_props)
shot.create(api=api)
return shot
def tasks_for_shots(self, shots, known_task_types):
"""Returns a dict of tasks for each shot.
:param shots: list of shot nodes.
:param known_task_types: Collection of task type names. Any task with a
type not in this list will map the None key.
:returns: a dict {shot id: tasks}, where tasks is a dict in which the keys are the
task types, and the values are sets of tasks of that type.
:rtype: dict
"""
api = pillar_api()
id_to_shot = {}
shot_id_to_tasks = {}
for shot in shots:
shot_id = shot['_id']
id_to_shot[shot_id] = shot
shot_id_to_tasks[shot_id] = collections.defaultdict(set)
found = pillarsdk.Node.all({
'where': {
'node_type': node_type_task['name'],
'parent': {'$in': list(id_to_shot.keys())},
}
}, api=api)
known = set(known_task_types) # for fast lookups
# Now put the tasks into the right spot.
for task in found['_items']:
task_type = task.properties.task_type
if task_type not in known:
task_type = None
shot_id_to_tasks[task.parent][task_type].add(task)
return shot_id_to_tasks

View File

@@ -36,14 +36,25 @@ def index():
def for_project(project, attract_props):
api = pillar_api()
shots = pillarsdk.Node.all({
found = pillarsdk.Node.all({
'where': {
'project': project['_id'],
'node_type': node_type_shot['name'],
}}, api=api)
shots = found['_items']
tasks_for_shots = current_attract.shot_manager.tasks_for_shots(
shots,
attract_props.task_types.attract_shot,
)
# Append the task type onto which 'other' tasks are mapped.
task_types = attract_props.task_types.attract_shot + [None]
return render_template('attract/shots/for_project.html',
shots=shots['_items'],
shots=shots,
tasks_for_shots=tasks_for_shots,
task_types=task_types,
project=project,
attract_props=attract_props)

View File

@@ -25,7 +25,7 @@ class TaskManager(object):
self._log.info("Task '%s' logged in SVN: %s", task_id, log_entry)
def create_task(self, project, task_type=None):
def create_task(self, project, task_type=None, parent=None):
"""Creates a new task, owned by the current user.
:rtype: pillarsdk.Node
@@ -48,6 +48,8 @@ class TaskManager(object):
if task_type:
node_props['properties']['task_type'] = task_type
if parent:
node_props['parent'] = parent
task = pillarsdk.Node(node_props)
task.create(api=api)