Page MenuHome

routes.py
No OneTemporary

File Metadata

Created
Thu, Jan 23, 6:25 AM

routes.py

import logging
from flask import Blueprint, render_template, request
import flask
import pillarsdk
import pillar.api.utils
from pillar.web.system_util import pillar_api
from attract.modules import attract_project_view
from attract.node_types.shot import node_type_shot
from attract import current_attract
blueprint = Blueprint('attract.shots', __name__, url_prefix='/shots')
perproject_blueprint = Blueprint('attract.shots.perproject', __name__,
url_prefix='/<project_url>/shots')
log = logging.getLogger(__name__)
@blueprint.route('/')
def index():
api = pillar_api()
# Find projects that are set up for Attract.
projects = pillarsdk.Project.all({
'where': {
'extension_props.attract': {'$exists': 1},
'node_types.name': node_type_shot['name'],
}}, api=api)
return render_template('attract/shots/index.html',
projects=projects['_items'])
@perproject_blueprint.route('/', endpoint='index')
@perproject_blueprint.route('/with-task/<task_id>', endpoint='index')
@attract_project_view(extension_props=True)
def for_project(project, attract_props, task_id=None):
api = pillar_api()
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,
tasks_for_shots=tasks_for_shots,
task_types=task_types,
open_task_id=task_id,
project=project,
attract_props=attract_props)
@perproject_blueprint.route('/<shot_id>')
@attract_project_view(extension_props=True)
def view_shot(project, attract_props, shot_id):
api = pillar_api()
shot = pillarsdk.Node.find(shot_id, api=api)
node_type = project.get_node_type(node_type_shot['name'])
if request.is_xhr:
template = 'attract/shots/view_shot_embed.html'
else:
template = 'attract/shots/view_shot.html'
return render_template(template,
shot=shot,
project=project,
shot_node_type=node_type,
attract_props=attract_props)
@perproject_blueprint.route('/<shot_id>', methods=['POST'])
@attract_project_view()
def save(project, shot_id):
log.info('Saving shot %s', shot_id)
log.debug('Form data: %s', request.form)
shot_dict = request.form.to_dict()
shot = current_attract.shot_manager.edit_shot(shot_id, **shot_dict)
return pillar.api.utils.jsonify(shot.to_dict())
# TODO: remove GET method once Pablo has made a proper button to call this URL with a POST.
@perproject_blueprint.route('/create', methods=['POST', 'GET'])
@attract_project_view()
def create_shot(project):
shot = current_attract.shot_manager.create_shot(project)
resp = flask.make_response()
resp.headers['Location'] = flask.url_for('.view_shot',
project_url=project['url'],
shot_id=shot['_id'])
resp.status_code = 201
return resp

Event Timeline