Initial steps for procedural nodes
This commit is contained in:
parent
a1c326f2c0
commit
cc534ae4ef
@ -13,4 +13,4 @@ class NodeTypeForm(Form):
|
||||
name = TextField('Node Name', validators=[DataRequired()])
|
||||
url = TextField('Url', validators=[DataRequired()])
|
||||
description = TextAreaField('Description', validators=[DataRequired()])
|
||||
is_extended = BooleanField('Is extended')
|
||||
is_extended = BooleanField('Is extended')
|
||||
|
@ -31,15 +31,6 @@ except OSError:
|
||||
pass
|
||||
|
||||
|
||||
class Status(db.Model):
|
||||
id = db.Column(db.Integer, primary_key = True)
|
||||
name = db.Column(db.String(120), nullable=False)
|
||||
url = db.Column(db.String(120), nullable=False)
|
||||
description = db.Column(db.Text)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class NodeType(db.Model):
|
||||
id = db.Column(db.Integer, primary_key = True)
|
||||
name = db.Column(db.String(120), nullable=False)
|
||||
@ -50,7 +41,6 @@ class NodeType(db.Model):
|
||||
return self.name
|
||||
|
||||
|
||||
|
||||
class Node(db.Model):
|
||||
id = db.Column(db.Integer, primary_key = True)
|
||||
name = db.Column(db.String(120), nullable=False)
|
||||
@ -67,9 +57,36 @@ class Node(db.Model):
|
||||
node_type_id = db.Column(db.Integer(), db.ForeignKey(NodeType.id))
|
||||
node_type = db.relationship(NodeType, backref='Node')
|
||||
|
||||
status_id = db.Column(db.Integer(), db.ForeignKey(Status.id))
|
||||
status = db.relationship(Status, backref='Node')
|
||||
properties = db.relationship('NodeProperties', backref='Node')
|
||||
|
||||
def get_property(self, name):
|
||||
for p in self.properties:
|
||||
if p.custom_field.name_url == name:
|
||||
return p
|
||||
print 'p'
|
||||
return None
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class CustomFields(db.Model):
|
||||
id = db.Column(db.Integer, primary_key = True)
|
||||
node_type_id = db.Column(db.Integer(), db.ForeignKey(NodeType.id))
|
||||
node_type = db.relationship(NodeType, backref='CustomField')
|
||||
|
||||
field_type = db.Column(db.String(128))
|
||||
order = db.Column(db.Integer())
|
||||
name = db.Column(db.String(128))
|
||||
name_url = db.Column(db.String(128))
|
||||
description = db.Column(db.Text())
|
||||
|
||||
|
||||
class NodeProperties(db.Model):
|
||||
id = db.Column(db.Integer, primary_key = True)
|
||||
node_id = db.Column(db.Integer(), db.ForeignKey(Node.id))
|
||||
|
||||
custom_field_id = db.Column(db.Integer(), db.ForeignKey(CustomFields.id))
|
||||
custom_field = db.relationship(CustomFields, backref='NodeProperties')
|
||||
|
||||
value = db.Column(db.Text())
|
||||
|
@ -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
|
||||
from application.modules.nodes.models import Node, NodeType, NodeProperties
|
||||
from application.modules.shots.models import NodeShot
|
||||
|
||||
|
||||
@ -23,19 +23,24 @@ shots = Blueprint('shots', __name__)
|
||||
@shots.route("/")
|
||||
def index():
|
||||
shots = []
|
||||
|
||||
for n in Node.query.all():
|
||||
for p in n.properties:
|
||||
print p.value
|
||||
|
||||
for shot in Node.query.\
|
||||
join(NodeType).\
|
||||
filter(NodeType.url == 'shot'):
|
||||
status = None
|
||||
if shot.status:
|
||||
status = shot.status.name
|
||||
shots.append(dict(
|
||||
# if shot.status:
|
||||
# status = shot.status.name
|
||||
s = dict(
|
||||
id=shot.id,
|
||||
name=shot.name,
|
||||
description=shot.description,
|
||||
duration=shot.node_shot[0].duration,
|
||||
status=status,
|
||||
notes=shot.node_shot[0].notes))
|
||||
description=shot.description)
|
||||
for node_property in shot.properties:
|
||||
s[node_property.custom_field.name_url] = node_property.value
|
||||
shots.append(s)
|
||||
return render_template('shots/index.html',
|
||||
title='shots',
|
||||
shots=shots)
|
||||
@ -48,7 +53,7 @@ def view(shot_id):
|
||||
return render_template('shots/view.html',
|
||||
title='shots',
|
||||
shot=shot,
|
||||
notes=shot.node_shot[0].notes)
|
||||
notes=shot.get_property('notes'))
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@ -75,6 +80,101 @@ def add():
|
||||
return render_template('shots/add.html', form=form)
|
||||
|
||||
|
||||
|
||||
@shots.route("/procedural", methods=('GET', 'POST'))
|
||||
def procedural():
|
||||
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 import HiddenField
|
||||
|
||||
from application.modules.nodes.models import CustomFields
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
node_type = NodeType.query.filter_by(url='shot').first()
|
||||
class ProceduralForm(Form):
|
||||
pass
|
||||
|
||||
setattr(ProceduralForm,
|
||||
'name',
|
||||
TextField('Node Name', validators=[DataRequired()]))
|
||||
setattr(ProceduralForm,
|
||||
'description',
|
||||
TextAreaField('Description', validators=[DataRequired()]))
|
||||
setattr(ProceduralForm,
|
||||
'node_type_id',
|
||||
HiddenField(default=node_type.id))
|
||||
|
||||
for custom_field in CustomFields.query\
|
||||
.join(NodeType)\
|
||||
.filter(NodeType.url == 'shot'):
|
||||
|
||||
if custom_field.field_type == 'text':
|
||||
field_properties = TextAreaField(custom_field.name,
|
||||
validators=[DataRequired()])
|
||||
elif custom_field.field_type == 'integer':
|
||||
field_properties = IntegerField(custom_field.name,
|
||||
validators=[DataRequired()])
|
||||
elif custom_field.field_type == 'select':
|
||||
options = Node.query\
|
||||
.join(NodeType)\
|
||||
.filter(NodeType.url==custom_field.name_url)\
|
||||
.all()
|
||||
print options
|
||||
field_properties = SelectField(custom_field.name,
|
||||
coerce=int,
|
||||
choices=[(option.id, option.name) for option in options] )
|
||||
#choices=[(status.id, status.name) for status in statuses])
|
||||
|
||||
setattr(ProceduralForm, custom_field.name_url, field_properties)
|
||||
|
||||
form = ProceduralForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
node = Node(
|
||||
name=form.name.data,
|
||||
description=form.description.data,
|
||||
node_type_id=form.node_type_id.data)
|
||||
db.session.add(node)
|
||||
db.session.commit()
|
||||
|
||||
for custom_field in CustomFields.query\
|
||||
.join(NodeType)\
|
||||
.filter(NodeType.url == 'shot'):
|
||||
|
||||
for field in form:
|
||||
if field.name == custom_field.name_url:
|
||||
node_property = NodeProperties(
|
||||
node_id=node.id,
|
||||
custom_field_id=custom_field.id,
|
||||
value=field.data)
|
||||
db.session.add(node_property)
|
||||
db.session.commit()
|
||||
|
||||
return redirect('/')
|
||||
else:
|
||||
print form.errors
|
||||
# if form.validate_on_submit():
|
||||
# shot_type = NodeType.query.filter_by(url='shot').first()
|
||||
# shot = Node(
|
||||
# name=form.name.data,
|
||||
# description=form.description.data,
|
||||
# node_type_id=shot_type.id,
|
||||
# status_id=form.status_id.data)
|
||||
# # Create entry in the attached node table
|
||||
# shot.node_shot = [NodeShot(
|
||||
# duration=form.duration.data,
|
||||
# notes=form.notes.data)]
|
||||
|
||||
# db.session.add(shot)
|
||||
# db.session.commit()
|
||||
# return redirect('/')
|
||||
return render_template('shots/procedural.html', form=form)
|
||||
|
||||
|
||||
@shots.route("/edit/<int:shot_id>", methods=('GET', 'POST'))
|
||||
def edit(shot_id):
|
||||
shot = Node.query.get(shot_id)
|
||||
@ -84,7 +184,6 @@ 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()]
|
||||
|
||||
if form.validate_on_submit():
|
||||
print shot.node_shot
|
||||
|
@ -26,7 +26,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{shot['duration']}}</td>
|
||||
<td><span class="label label-default" style="background-color:<?php echo $shot['status_color'] ?>">{{shot['status']}}</span></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>
|
||||
{% if shot['notes'] %}
|
||||
|
28
attract/application/templates/shots/procedural.html
Normal file
28
attract/application/templates/shots/procedural.html
Normal file
@ -0,0 +1,28 @@
|
||||
{% extends 'layout.html' %}
|
||||
|
||||
{% block body %}
|
||||
<div class="col-md-9">
|
||||
<h2>Add shot</h2>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<form method="POST" action="{{url_for('shots.procedural')}}">
|
||||
{% for field in form %}
|
||||
{% if field.name == 'csrf_token' %}
|
||||
{{ field }}
|
||||
{% else %}
|
||||
{% if field.type == "HiddenField" %}
|
||||
{{ field }}
|
||||
{% else %}
|
||||
<div class="form-group">
|
||||
{{ field.label }}
|
||||
{{ field(class='form-control') }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<input class="btn btn-default" type="submit" value="Create Shot">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -11,7 +11,7 @@
|
||||
<p>{{shot['description']}}</p>
|
||||
<p>
|
||||
{% if notes %}
|
||||
{{notes}}
|
||||
{{notes.value}}
|
||||
{% else %}
|
||||
No notes at the moment
|
||||
{% endif %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user