Index and deletion for generic nodes
This commit is contained in:
@@ -65,6 +65,15 @@ def add():
|
|||||||
return render_template('node_types/add.html', form=form)
|
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'])
|
@nodes.route("/<node_type>/add", methods=['GET', 'POST'])
|
||||||
def add(node_type):
|
def add(node_type):
|
||||||
"""Generic function to add a node of any type
|
"""Generic function to add a node of any type
|
||||||
@@ -109,4 +118,14 @@ def edit(node_id):
|
|||||||
|
|
||||||
return render_template('nodes/edit.html',
|
return render_template('nodes/edit.html',
|
||||||
node=node,
|
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'
|
||||||
|
@@ -13,6 +13,13 @@ from application import db
|
|||||||
|
|
||||||
from application.modules.nodes.models import Node, NodeType, NodeProperties
|
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):
|
class NodeTypeForm(Form):
|
||||||
name = TextField('Name', validators=[DataRequired()])
|
name = TextField('Name', validators=[DataRequired()])
|
||||||
|
@@ -57,7 +57,8 @@ class Node(db.Model):
|
|||||||
node_type_id = db.Column(db.Integer(), db.ForeignKey(NodeType.id))
|
node_type_id = db.Column(db.Integer(), db.ForeignKey(NodeType.id))
|
||||||
node_type = db.relationship(NodeType, backref='Node')
|
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):
|
def get_property(self, name):
|
||||||
for p in self.properties:
|
for p in self.properties:
|
||||||
|
@@ -47,7 +47,8 @@
|
|||||||
<li><a role="menuitem" tabindex="-1" href="">Tasks</a></li>
|
<li><a role="menuitem" tabindex="-1" href="">Tasks</a></li>
|
||||||
<li><a role="menuitem" tabindex="-1" href="">Profile</a></li>
|
<li><a role="menuitem" tabindex="-1" href="">Profile</a></li>
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
<li><a role="menuitem" tabindex="-1" href="{{url_for('node_types.index')}}">Task Types</a></li>
|
<li><a role="menuitem" tabindex="-1" href="{{url_for('node_types.index')}}">Node Types</a></li>
|
||||||
|
<li><a role="menuitem" tabindex="-1" href="{{url_for('nodes.index')}}">All Nodes</a></li>
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
<li><a role="menuitem" tabindex="-1" href="">Log out</a></li>
|
<li><a role="menuitem" tabindex="-1" href="">Log out</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -64,7 +65,7 @@
|
|||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
<a href="{{url_for('shots.index')}}" class="list-group-item {% if title == 'shots' %}active{% endif %}">Shots</a>
|
<a href="{{url_for('shots.index')}}" class="list-group-item {% if title == 'shots' %}active{% endif %}">Shots</a>
|
||||||
<a href="/stats" class="list-group-item {% if title == 'stats' %}active{% endif %}">Stats</a>
|
<a href="#" class="list-group-item {% if title == 'stats' %}active{% endif %}">Assets</a>
|
||||||
</div>
|
</div>
|
||||||
</div><!--/end col-md-3 -->
|
</div><!--/end col-md-3 -->
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -21,6 +21,10 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<input class="btn btn-default" type="submit" value="Edit {{ node.node_type.name }}">
|
<input class="btn btn-default" type="submit" value="Edit {{ node.node_type.name }}">
|
||||||
|
<div class="pull-right">
|
||||||
|
<a class="btn btn-default" href="#">Cancel</a>
|
||||||
|
<a class="btn btn-danger" href="{{url_for('nodes.delete', node_id=node.id)}}">Delete</a>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
47
attract/application/templates/nodes/index.html
Normal file
47
attract/application/templates/nodes/index.html
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="col-md-9">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped" id="nodes">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th width="8%"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for node in nodes %}
|
||||||
|
<tr id="row_{{node.id}}">
|
||||||
|
<td><a href="#">{{node.name}}</a></td>
|
||||||
|
<td>
|
||||||
|
{% if node.description %}
|
||||||
|
{{node.description|truncate(25)}}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a class="btn btn-default btn-xs" href="{{url_for('nodes.edit', node_id=node.id)}}"><i class="glyphicon glyphicon-edit"></i> Edit</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<a href="#" class="btn btn-default">Add</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Reference in New Issue
Block a user