Page MenuHome

shots.py
No OneTemporary

shots.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.shot import node_type_shot
from . 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')
@attract_project_view(extension_props=True)
def for_project(project, attract_props):
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,
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)
return render_template('attract/shots/shot.html',
shot=shot,
project=project,
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 flask.jsonify({'shot_id': shot_id, 'etag': shot._etag, 'time': shot._updated })
# 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

File Metadata

Mime Type
text/x-python
Expires
Sun, Aug 14, 12:10 AM (2 d)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
88/9d/800dac8280a66e4a51a403176218

Event Timeline