76 lines
2.3 KiB
Python
76 lines
2.3 KiB
Python
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()
|
|
|
|
shots = pillarsdk.Node.all({
|
|
'where': {
|
|
'project': project['_id'],
|
|
'node_type': node_type_shot['name'],
|
|
}}, api=api)
|
|
|
|
return render_template('attract/shots/for_project.html',
|
|
shots=shots['_items'],
|
|
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)
|
|
|
|
|
|
# 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
|