Shot create renamed to add

This commit is contained in:
Francesco Siddi 2014-05-19 00:10:08 +02:00
parent 08f95dcb99
commit bf4399e5b3
4 changed files with 49 additions and 42 deletions

View File

@ -24,7 +24,10 @@ shots = Blueprint('shots', __name__)
@shots.route("/") @shots.route("/")
def index(): def index():
"""Full list of shots in the current project"""
shots = [] shots = []
# Get all nodes with type 'shot'
# TODO (fsiddi): add project filtering
for shot in Node.query.\ for shot in Node.query.\
join(NodeType).\ join(NodeType).\
filter(NodeType.url == 'shot'): filter(NodeType.url == 'shot'):
@ -43,56 +46,55 @@ def index():
@shots.route("/view/<int:shot_id>") @shots.route("/view/<int:shot_id>")
def view(shot_id): def view(shot_id):
shot = Node.query.get(shot_id) """View a single shot"""
if shot and shot.node_type.url == 'shot': shot = Node.query.get_or_404(shot_id)
return render_template('shots/view.html', if shot.node_type.url == 'shot':
title='shots', return render_template('shots/view.html',
shot=shot) title='shots',
else: shot=shot)
abort(404)
class ShotForm(Form): class ShotForm(Form):
"""Form class used for shot creation and editing"""
name = TextField('Shot Name', validators=[DataRequired()]) name = TextField('Shot Name', validators=[DataRequired()])
description = TextField('Description', validators=[DataRequired()]) description = TextField('Description', validators=[DataRequired()])
@shots.route("/create", methods=('GET', 'POST')) @shots.route("/add", methods=('GET', 'POST'))
def create(): def add():
form = ShotForm() """Add a shot to the project"""
if form.validate_on_submit(): form = ShotForm()
shot_type = NodeType.query.filter_by(name='shot').first() if form.validate_on_submit():
shot = Node( shot_type = NodeType.query.filter_by(name='shot').first()
name=form.name.data, shot = Node(
description=form.description.data, name=form.name.data,
node_type_id=shot_type.id) description=form.description.data,
db.session.add(shot) node_type_id=shot_type.id)
db.session.commit() db.session.add(shot)
return redirect('/') db.session.commit()
return render_template('shots/create.html', form=form) return redirect('/')
return render_template('shots/add.html', form=form)
@shots.route("/edit/<int:shot_id>", methods=('GET', 'POST')) @shots.route("/edit/<int:shot_id>", methods=('GET', 'POST'))
def edit(shot_id): def edit(shot_id):
shot = Node.query.get(shot_id) shot = Node.query.get_or_404(shot_id)
form = ShotForm( form = ShotForm(
name=shot.name, name=shot.name,
description=shot.description) description=shot.description)
if form.validate_on_submit(): if form.validate_on_submit():
shot.name = form.name.data shot.name = form.name.data
shot.description=form.description.data shot.description=form.description.data
db.session.commit() db.session.commit()
return redirect('/') return redirect('/')
return render_template( return render_template(
'shots/edit.html', 'shots/edit.html',
form=form, form=form,
shot_id=shot_id) shot_id=shot_id)
@shots.route("/delete/<int:shot_id>") @shots.route("/delete/<int:shot_id>")
def delete(shot_id): def delete(shot_id):
shot = Node.query.get(shot_id) shot = Node.query.get_or_404(shot_id)
if shot:
db.session.delete(shot) db.session.delete(shot)
return redirect('/') return redirect('/')
else:
abort(404)

View File

@ -95,6 +95,11 @@ class Node(db.Model):
class NodeShot(db.Model):
id = db.Column(db.Integer, primary_key = True)
start_frame = db.Column(db.Integer)
end_frame = db.Column(db.Integer)
# Create Many to Many table # Create Many to Many table
""" """
assets_tags_table = db.Table('assets_tags', db.Model.metadata, assets_tags_table = db.Table('assets_tags', db.Model.metadata,

View File

@ -2,10 +2,10 @@
{% block body %} {% block body %}
<div class="col-md-9"> <div class="col-md-9">
<h2>Create shot</h2> <h2>Add shot</h2>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<form method="POST" action="{{url_for('shots.create')}}"> <form method="POST" action="{{url_for('shots.add')}}">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<div class="form-group"> <div class="form-group">
{{ form.name.label }} {{ form.name.label }}
@ -15,7 +15,7 @@
{{ form.description.label }} {{ form.description.label }}
{{ form.description(size=20, class='form-control') }} {{ form.description(size=20, class='form-control') }}
</div> </div>
<input class="btn btn-default" type="submit" value="Create Shot"> <input class="btn btn-default" type="submit" value="Add Shot">
</form> </form>
</div> </div>
</div> </div>

View File

@ -48,7 +48,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<a href="{{url_for('shots.create')}}" class="btn btn-default">Create</a> <a href="{{url_for('shots.add')}}" class="btn btn-default">Add</a>
</div> </div>
</div> </div>
</div> </div>