Moved some task fetching functionality into TaskManager.

This commit is contained in:
2016-10-05 11:25:01 +02:00
parent 79e0969c73
commit 426635cc45
2 changed files with 34 additions and 18 deletions

View File

@@ -95,6 +95,38 @@ class TaskManager(object):
task = pillarsdk.Node({'_id': task_id, '_etag': etag})
task.delete(api=api)
def tasks_for_user(self, user_id):
"""Returns the tasks for the given user.
:returns: {'_items': [task, task, ...], '_meta': {Eve metadata}}
"""
api = pillar_api()
# TODO: also include tasks assigned to any of the user's groups.
tasks = pillarsdk.Node.all({
'where': {
'properties.assigned_to.users': user_id,
'node_type': node_type_task['name'],
}
}, api=api)
return tasks
def tasks_for_project(self, project_id):
"""Returns the tasks for the given project.
:returns: {'_items': [task, task, ...], '_meta': {Eve metadata}}
"""
api = pillar_api()
tasks = pillarsdk.Node.all({
'where': {
'project': project_id,
'node_type': node_type_task['name'],
}}, api=api)
return tasks
def setup_app(app):
from . import eve_hooks

View File

@@ -24,16 +24,7 @@ def index():
if not user.is_authenticated:
return render_template('attract/tasks/index.html')
api = pillar_api()
# TODO: also include tasks assigned to any of the user's groups.
tasks = pillarsdk.Node.all({
'where': {
'properties.assigned_to.users': user.objectid,
'node_type': node_type_task['name'],
}
}, api=api)
tasks = current_attract.task_manager.tasks_for_user(user.objectid)
return render_template('attract/tasks/for_user.html',
tasks=tasks['_items'],
task_count=tasks['_meta']['total'])
@@ -52,14 +43,7 @@ def delete(task_id):
@perproject_blueprint.route('/', endpoint='index')
@attract_project_view()
def for_project(project, task_id=None):
api = pillar_api()
tasks = pillarsdk.Node.all({
'where': {
'project': project['_id'],
'node_type': node_type_task['name'],
}}, api=api)
tasks = current_attract.task_manager.tasks_for_project(project['_id'])
return render_template('attract/tasks/for_project.html',
tasks=tasks['_items'],
open_task_id=task_id,