Page MenuHome

tasks.py
No OneTemporary

File Metadata

Created
Wed, Oct 23, 11:16 PM

tasks.py

import logging
from flask import Blueprint, render_template, request
import flask
import flask_login
import pillarsdk
from pillar.web.system_util import pillar_api
from .modules import attract_project_view
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': 'attract.task',
}}, api=api)
return render_template('attract/tasks/for_project.html',
tasks=tasks['_items'],
project=project)
@blueprint.route('/<project_url>/<task_id>')
@attract_project_view()
def view_embed_task(project, task_id):
api = pillar_api()
task = pillarsdk.Node.find(task_id, api=api)
node_type = project.get_node_type('attract.task')
return render_template('attract/tasks/view_task_embed.html',
task=task,
project=project,
task_node_type=node_type)
@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)
api = pillar_api()
task = pillarsdk.Node.find(task_id, api=api)
task.name = request.form['name']
task.description = request.form['description']
task.properties.status = request.form['status']
task.update(api=api)
return flask.jsonify({'task_id': task_id, 'etag': task._etag})
@blueprint.route('/<project_url>/create')
@attract_project_view()
def create_task(project):
api = pillar_api()
node_type = project.get_node_type('attract.task')
node_props = dict(
name='New task',
project=project['_id'],
user=flask_login.current_user.objectid,
node_type=node_type['name'],
properties={
'status': node_type['dyn_schema']['status']['default'],
},
)
task = pillarsdk.Node(node_props)
task.create(api=api)
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 resp

Event Timeline