Index and deletion for generic nodes

This commit is contained in:
2015-02-03 01:04:58 +01:00
parent 74dbe65834
commit 2ac2917645
6 changed files with 83 additions and 4 deletions

View File

@@ -65,6 +65,15 @@ def add():
return render_template('node_types/add.html', form=form)
@nodes.route("/", methods=['GET', 'POST'])
def index():
"""Generic function to list all nodes
"""
nodes = Node.query.all()
return render_template('nodes/index.html',
nodes=nodes)
@nodes.route("/<node_type>/add", methods=['GET', 'POST'])
def add(node_type):
"""Generic function to add a node of any type
@@ -109,4 +118,14 @@ def edit(node_id):
return render_template('nodes/edit.html',
node=node,
form=form)
form=form)
@nodes.route("/<int:node_id>/delete", methods=['GET', 'POST'])
def delete(node_id):
"""Generic node deletion
"""
node = Node.query.get_or_404(node_id)
db.session.delete(node)
db.session.commit()
return 'ok'

View File

@@ -13,6 +13,13 @@ from application import db
from application.modules.nodes.models import Node, NodeType, NodeProperties
class CustomFieldForm(Form):
field_type = TextField('Field Type', validators=[DataRequired()])
name = TextField('Name', validators=[DataRequired()])
name_url = TextField('Url', validators=[DataRequired()])
description = TextAreaField('Description', validators=[DataRequired()])
is_required = BooleanField('Is extended')
class NodeTypeForm(Form):
name = TextField('Name', validators=[DataRequired()])

View File

@@ -57,7 +57,8 @@ class Node(db.Model):
node_type_id = db.Column(db.Integer(), db.ForeignKey(NodeType.id))
node_type = db.relationship(NodeType, backref='Node')
properties = db.relationship('NodeProperties', backref='Node')
properties = db.relationship('NodeProperties', backref='Node',
cascade="all, delete, delete-orphan")
def get_property(self, name):
for p in self.properties: