NodeType editing
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
from flask import abort
|
||||
from flask import Blueprint
|
||||
from flask import jsonify
|
||||
from flask import render_template
|
||||
from flask import redirect
|
||||
from flask import request
|
||||
from flask import flash
|
||||
from flask import url_for
|
||||
|
||||
from application import db
|
||||
|
||||
from application.modules.nodes.models import Node, NodeType
|
||||
from application.modules.nodes.forms import NodeTypeForm
|
||||
|
||||
|
||||
# Name of the Blueprint
|
||||
nodes = Blueprint('nodes', __name__)
|
||||
|
||||
@nodes.route("/")
|
||||
def index():
|
||||
"""Display the node types
|
||||
"""
|
||||
node_types = [t for t in NodeType.query.all()]
|
||||
|
||||
return render_template('nodes/index.html',
|
||||
title='nodes',
|
||||
node_types=node_types)
|
||||
|
||||
shots = []
|
||||
for shot in Node.query.\
|
||||
join(NodeType).\
|
||||
filter(NodeType.url == 'shot'):
|
||||
status = None
|
||||
if shot.status:
|
||||
status = shot.status.name
|
||||
shots.append(dict(
|
||||
id=shot.id,
|
||||
name=shot.name,
|
||||
description=shot.description,
|
||||
duration=shot.node_shot[0].duration,
|
||||
status=status,
|
||||
notes=shot.node_shot[0].notes))
|
||||
return render_template('shots/index.html',
|
||||
title='shots',
|
||||
shots=shots)
|
||||
|
||||
|
||||
@nodes.route("/create", methods=('GET', 'POST'))
|
||||
def create():
|
||||
form = NodeTypeForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
node_type = NodeType(
|
||||
name=form.name.data,
|
||||
description=form.description.data,
|
||||
url=form.url.data)
|
||||
|
||||
db.session.add(node_type)
|
||||
db.session.commit()
|
||||
|
||||
return redirect(url_for('nodes.index'))
|
||||
return render_template('nodes/create.html', form=form)
|
||||
|
16
attract/application/modules/nodes/forms.py
Normal file
16
attract/application/modules/nodes/forms.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from flask_wtf import Form
|
||||
from wtforms import TextField
|
||||
from wtforms import BooleanField
|
||||
from wtforms import SelectField
|
||||
from wtforms import TextAreaField
|
||||
from wtforms import IntegerField
|
||||
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
from application.modules.nodes.models import Node, NodeType
|
||||
|
||||
class NodeTypeForm(Form):
|
||||
name = TextField('Node Name', validators=[DataRequired()])
|
||||
url = TextField('Url', validators=[DataRequired()])
|
||||
description = TextAreaField('Description', validators=[DataRequired()])
|
||||
is_extended = BooleanField('Is extended')
|
@@ -50,12 +50,6 @@ class NodeType(db.Model):
|
||||
return self.name
|
||||
|
||||
|
||||
# Create Many to Many table
|
||||
# nodes_assets_table = db.Table('nodes_assets', db.Model.metadata,
|
||||
# db.Column('node_id', db.Integer, db.ForeignKey('node.id')),
|
||||
# db.Column('asset_id', db.Integer, db.ForeignKey('asset.id'))
|
||||
# )
|
||||
|
||||
|
||||
class Node(db.Model):
|
||||
id = db.Column(db.Integer, primary_key = True)
|
||||
@@ -76,8 +70,6 @@ class Node(db.Model):
|
||||
status_id = db.Column(db.Integer(), db.ForeignKey(Status.id))
|
||||
status = db.relationship(Status, backref='Node')
|
||||
|
||||
#assets = db.relationship('Asset', secondary=nodes_assets_table)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
@@ -13,7 +13,7 @@ from sqlalchemy.orm import aliased
|
||||
from application import db
|
||||
|
||||
from application.modules.shots.forms import ShotForm
|
||||
from application.modules.nodes.models import Node, NodeType, Status
|
||||
from application.modules.nodes.models import Node, NodeType
|
||||
from application.modules.shots.models import NodeShot
|
||||
|
||||
|
||||
@@ -56,8 +56,7 @@ def view(shot_id):
|
||||
@shots.route("/create", methods=('GET', 'POST'))
|
||||
def create():
|
||||
form = ShotForm()
|
||||
# Populate dropdown select with available Statuses
|
||||
form.status_id.choices = [(status.id, status.name) for status in Status.query.all()]
|
||||
|
||||
if form.validate_on_submit():
|
||||
shot_type = NodeType.query.filter_by(url='shot').first()
|
||||
shot = Node(
|
||||
@@ -85,7 +84,7 @@ def edit(shot_id):
|
||||
description=shot.description,
|
||||
duration=shot.node_shot[0].duration,
|
||||
note=shot.node_shot[0].notes)
|
||||
form.status_id.choices = [(status.id, status.name) for status in Status.query.all()]
|
||||
#form.status_id.choices = [(status.id, status.name) for status in Status.query.all()]
|
||||
|
||||
if form.validate_on_submit():
|
||||
print shot.node_shot
|
||||
|
@@ -7,9 +7,18 @@ from wtforms import IntegerField
|
||||
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
from application.modules.nodes.models import Node, NodeType
|
||||
|
||||
class ShotForm(Form):
|
||||
statuses = Node.query\
|
||||
.join(NodeType)\
|
||||
.filter(NodeType.url == 'shot_status')\
|
||||
.all()
|
||||
|
||||
name = TextField('Shot Name', validators=[DataRequired()])
|
||||
description = TextAreaField('Description', validators=[DataRequired()])
|
||||
status_id = SelectField('Status', coerce=int)
|
||||
status_id = SelectField('Status',
|
||||
coerce=int,
|
||||
choices=[(status.id, status.name) for status in statuses])
|
||||
duration = IntegerField('Duration')
|
||||
notes = TextAreaField('Notes')
|
||||
|
Reference in New Issue
Block a user