Page MenuHome

routes.py
No OneTemporary

File Metadata

Created
Tue, Nov 19, 8:04 PM

routes.py

import logging
import flask_login
from flask import Blueprint, render_template, request
import flask
import werkzeug.exceptions as wz_exceptions
import pillarsdk
import pillar.api.utils
from pillar.web.system_util import pillar_api
from attract.routes import attract_project_view
from attract.node_types.shot import node_type_shot
from attract import current_attract, ROLES_REQUIRED_TO_VIEW_ITEMS
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():
projects = current_attract.attract_projects()
return render_template('attract/shots/index.html',
projects=projects['_items'])
@perproject_blueprint.route('/', endpoint='index')
@perproject_blueprint.route('/with-task/<task_id>', endpoint='with_task')
@attract_project_view(extension_props=True)
def for_project(project, attract_props, task_id=None, shot_id=None):
api = pillar_api()
found = pillarsdk.Node.all({
'where': {
'project': project['_id'],
'node_type': node_type_shot['name'],
},
'sort': [
('properties.cut_in_timeline_in_frames', 1),
]
}, 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,
open_shot_id=shot_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):
if not request.is_xhr:
return for_project(project, attract_props, shot_id=shot_id)
# Shot list is public, shot details are not.
if not flask_login.current_user.has_role(*ROLES_REQUIRED_TO_VIEW_ITEMS):
raise wz_exceptions.Forbidden()
api = pillar_api()
shot = pillarsdk.Node.find(shot_id, api=api)
node_type = project.get_node_type(node_type_shot['name'])
return render_template('attract/shots/view_shot_embed.html',
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()
current_attract.shot_manager.edit_shot(shot_id, **shot_dict)
# Return the patched node in all its glory.
api = pillar_api()
shot = pillarsdk.Node.find(shot_id, api=api)
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 flask.make_response(flask.jsonify({'shot_id': shot['_id']}), 201)

Event Timeline