diff --git a/attract/application/controllers/shots.py b/attract/application/controllers/shots.py index 5a8c9d02..a84a5813 100644 --- a/attract/application/controllers/shots.py +++ b/attract/application/controllers/shots.py @@ -24,7 +24,10 @@ shots = Blueprint('shots', __name__) @shots.route("/") def index(): + """Full list of shots in the current project""" shots = [] + # Get all nodes with type 'shot' + # TODO (fsiddi): add project filtering for shot in Node.query.\ join(NodeType).\ filter(NodeType.url == 'shot'): @@ -43,56 +46,55 @@ def index(): @shots.route("/view/") def view(shot_id): - shot = Node.query.get(shot_id) - if shot and shot.node_type.url == 'shot': - return render_template('shots/view.html', - title='shots', - shot=shot) - else: - abort(404) - + """View a single shot""" + shot = Node.query.get_or_404(shot_id) + if shot.node_type.url == 'shot': + return render_template('shots/view.html', + title='shots', + shot=shot) + class ShotForm(Form): + """Form class used for shot creation and editing""" name = TextField('Shot Name', validators=[DataRequired()]) description = TextField('Description', validators=[DataRequired()]) + -@shots.route("/create", methods=('GET', 'POST')) -def create(): - form = ShotForm() - if form.validate_on_submit(): - shot_type = NodeType.query.filter_by(name='shot').first() - shot = Node( - name=form.name.data, - description=form.description.data, - node_type_id=shot_type.id) - db.session.add(shot) - db.session.commit() - return redirect('/') - return render_template('shots/create.html', form=form) +@shots.route("/add", methods=('GET', 'POST')) +def add(): + """Add a shot to the project""" + form = ShotForm() + if form.validate_on_submit(): + shot_type = NodeType.query.filter_by(name='shot').first() + shot = Node( + name=form.name.data, + description=form.description.data, + node_type_id=shot_type.id) + db.session.add(shot) + db.session.commit() + return redirect('/') + return render_template('shots/add.html', form=form) @shots.route("/edit/", methods=('GET', 'POST')) def edit(shot_id): - shot = Node.query.get(shot_id) - form = ShotForm( - name=shot.name, - description=shot.description) - if form.validate_on_submit(): - shot.name = form.name.data - shot.description=form.description.data - db.session.commit() - return redirect('/') - return render_template( - 'shots/edit.html', - form=form, - shot_id=shot_id) + shot = Node.query.get_or_404(shot_id) + form = ShotForm( + name=shot.name, + description=shot.description) + if form.validate_on_submit(): + shot.name = form.name.data + shot.description=form.description.data + db.session.commit() + return redirect('/') + return render_template( + 'shots/edit.html', + form=form, + shot_id=shot_id) @shots.route("/delete/") def delete(shot_id): - shot = Node.query.get(shot_id) - if shot: + shot = Node.query.get_or_404(shot_id) db.session.delete(shot) return redirect('/') - else: - abort(404) diff --git a/attract/application/models/model.py b/attract/application/models/model.py index 3bffb810..b8f6d656 100644 --- a/attract/application/models/model.py +++ b/attract/application/models/model.py @@ -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 """ assets_tags_table = db.Table('assets_tags', db.Model.metadata, diff --git a/attract/application/templates/shots/create.html b/attract/application/templates/shots/add.html similarity index 75% rename from attract/application/templates/shots/create.html rename to attract/application/templates/shots/add.html index 5ac9716f..0a6e2f6a 100644 --- a/attract/application/templates/shots/create.html +++ b/attract/application/templates/shots/add.html @@ -2,10 +2,10 @@ {% block body %}
-

Create shot

+

Add shot

-
+ {{ form.hidden_tag() }}
{{ form.name.label }} @@ -15,7 +15,7 @@ {{ form.description.label }} {{ form.description(size=20, class='form-control') }}
- +
diff --git a/attract/application/templates/shots/index.html b/attract/application/templates/shots/index.html index bdc3d9de..850ae9ae 100644 --- a/attract/application/templates/shots/index.html +++ b/attract/application/templates/shots/index.html @@ -48,7 +48,7 @@
- Create + Add