Page MenuHome

tasks.py
No OneTemporary

File Metadata

Created
Sat, Oct 19, 4:46 PM

tasks.py

import logging
from flask import Blueprint, render_template, request, current_app
import flask
import flask_login
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_task_manager
blueprint = Blueprint('attract.tasks', __name__, url_prefix='/tasks')
log = logging.getLogger(__name__)
@blueprint.route('/')
def index():
return render_template('attract/tasks/index.html')
@blueprint.route('/<project_url>/')
@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)
@blueprint.route('/<project_url>/<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'])
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())
@blueprint.route('/<project_url>/<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 = current_task_manager.edit_task(task_id, **request.form.to_dict())
return flask.jsonify({'task_id': task_id, 'etag': task._etag, 'time': task._updated })
# TODO: remove GET method once Pablo has made a proper button to call this URL with a POST.
@blueprint.route('/<project_url>/create', methods=['POST', 'GET'])
@blueprint.route('/<project_url>/create/<task_type>', methods=['POST', 'GET'])
@attract_project_view()
def create_task(project, task_type=None):
task = current_task_manager.create_task(project, task_type=task_type)
resp = flask.make_response()
resp.headers['Location'] = flask.url_for('attract.tasks.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