Page MenuHome

tasks.py
No OneTemporary

File Metadata

Created
Fri, Oct 18, 10:40 AM

tasks.py

import logging
from flask import Blueprint, render_template, request
import flask
import pillarsdk
from pillar.web.system_util import pillar_api
from .modules import attract_project_view
from .node_types.task import node_type_task
from . import current_attract
blueprint = Blueprint('attract.tasks', __name__, url_prefix='/tasks')
perproject_blueprint = Blueprint('attract.tasks.perproject', __name__,
url_prefix='/<project_url>/tasks')
log = logging.getLogger(__name__)
@blueprint.route('/')
def index():
return render_template('attract/tasks/index.html')
@perproject_blueprint.route('/', endpoint='index')
@attract_project_view()
def for_project(project):
api = pillar_api()
tasks = pillarsdk.Node.all({
'where': {
'project': project['_id'],
'node_type': node_type_task['name'],
}}, api=api)
return render_template('attract/tasks/for_project.html',
tasks=tasks['_items'],
project=project)
@perproject_blueprint.route('/<task_id>')
@attract_project_view(extension_props=True)
def view_embed_task(project, attract_props, task_id):
api = pillar_api()
task = pillarsdk.Node.find(task_id, api=api)
node_type = project.get_node_type(node_type_task['name'])
# Fetch project users so that we can assign them tasks
users = project.get_users(api=api)
project.users = users['_items']
log.info('Attract properties: %s', attract_props)
return render_template('attract/tasks/view_task_embed.html',
task=task,
project=project,
task_node_type=node_type,
attract_props=attract_props.to_dict())
@perproject_blueprint.route('/<task_id>', methods=['POST'])
@attract_project_view()
def save(project, task_id):
log.info('Saving task %s', task_id)
log.debug('Form data: %s', request.form)
task_dict = request.form.to_dict()
task_dict['users'] = request.form.getlist('users')
task = current_attract.task_manager.edit_task(task_id, **task_dict)
return flask.jsonify({'task_id': task_id, 'etag': task._etag, 'time': task._updated })
@perproject_blueprint.route('/create', methods=['POST'])
@perproject_blueprint.route('/create/<task_type>', methods=['POST'])
@attract_project_view()
def create_task(project, task_type=None):
task = current_attract.task_manager.create_task(project, task_type=task_type)
resp = flask.make_response()
resp.headers['Location'] = flask.url_for('.view_embed_task',
project_url=project['url'],
task_id=task['_id'])
resp.status_code = 201
return flask.make_response(flask.jsonify({'task_id': task['_id']}), 201)

Event Timeline