changeset 87:e02724c84bae

Add deletion of (orphaned) relationships
author Benoît Allard <benoit.allard@greenbone.net>
date Thu, 09 Oct 2014 15:16:30 +0200
parents 2d41121ec991
children 521c0ec35338
files farol/producttree.py farol/templates/producttree/view.j2 farol/templates/producttree/view_product.j2
diffstat 3 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/farol/producttree.py	Thu Oct 09 14:50:37 2014 +0200
+++ b/farol/producttree.py	Thu Oct 09 15:16:30 2014 +0200
@@ -277,6 +277,24 @@
     ptree.addRelationship(rel)
     return redirect(url_for('.view'))
 
+@producttree.route('/relationship/<int:index>/del', methods=['POST'])
+@document_required
+@producttree_required
+def del_relationship(index):
+    rels = get_current()._producttree._relationships
+    if not (0 <= index < len(rels)):
+        flash('Relationship not found', 'danger')
+        abort(404)
+    rel = rels[index]
+
+    if not rel.isOrphaned():
+        flash('Not able to delete Relationship with Product', 'danger')
+        abort(403)
+
+    del rels[index]
+    return redirect(url_for('.view'))
+
+
 @producttree.route('/group/<groupid>/edit', methods=['GET', 'POST'])
 @document_required
 @producttree_required
--- a/farol/templates/producttree/view.j2	Thu Oct 09 14:50:37 2014 +0200
+++ b/farol/templates/producttree/view.j2	Thu Oct 09 15:16:30 2014 +0200
@@ -72,7 +72,7 @@
 {% call panel(heading="Relationships", badge=producttree._relationships | length, title=4) %}
   {% for relationship in producttree._relationships %}
     {% call panel() %}
-      <p><em>{{ cvrf.getProductForID(relationship._productreference)._name }}</em> as {{ relationship._relationtype | lower }} <em>{{ cvrf.getProductForID(relationship._relatestoproductreference)._name }}</em> (<a href="{{ url_for('.edit_relationship', index=loop.index0) }}">edit</a>)</p>
+      <div><em>{{ cvrf.getProductForID(relationship._productreference)._name }}</em> as {{ relationship._relationtype | lower }} <em>{{ cvrf.getProductForID(relationship._relatestoproductreference)._name }}</em> (<a href="{{ url_for('.edit_relationship', index=loop.index0) }}">edit</a>){% if relationship.isOrphaned() %}{{ delete_button(url_for('.del_relationship', index=loop.index0)) }}{% endif %}</div>
       {% if relationship._product %}<p><strong><a href="{{ url_for('.view_product', productid=relationship._product._productid) }}">{{ relationship._product._name }}</a></strong></p>{% endif %}
       {% if relationship.isOrphaned() %}
         <p class="text-danger">This relationship is <em>orphaned</em>. A product should be <a href="{{ url_for('.add_product') }}">created</a> as child of this one.</p>
--- a/farol/templates/producttree/view_product.j2	Thu Oct 09 14:50:37 2014 +0200
+++ b/farol/templates/producttree/view_product.j2	Thu Oct 09 15:16:30 2014 +0200
@@ -49,11 +49,14 @@
   {% endfor %}
   {% endcall %}
 {% endif %}
+
 <div>
 <p>This product belong to the following groups:</p>
 <ul>
 {% for group in cvrf._producttree._groups if product._productid in group._productids %}
   <li>{{ group.getTitle() }}</li>
+{% else %}
+  <li><em>None</em></li>
 {% endfor %}
 </ul>
 </div>

http://farol.wald.intevation.org