changeset 84:cc836f9e869e

Allow deletion of Products
author Benoît Allard <benoit.allard@greenbone.net>
date Thu, 09 Oct 2014 14:26:59 +0200
parents 2ecf13200e87
children b6a48669edb8
files farol/producttree.py farol/templates/producttree/view_product.j2
diffstat 2 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/farol/producttree.py	Thu Oct 09 14:26:33 2014 +0200
+++ b/farol/producttree.py	Thu Oct 09 14:26:59 2014 +0200
@@ -213,6 +213,22 @@
     ptree.addProduct(product)
     return redirect(url_for('.view'))
 
+@producttree.route('/product/<productid>/del', methods=['POST'])
+@document_required
+@producttree_required
+def del_product(productid):
+    cvrf = get_current()
+    ptree = cvrf._producttree
+    try:
+        product = cvrf.getProductForID(productid)
+    except KeyError:
+        abort(404)
+    product.unlink()
+    ptree._products.remove(product)
+    del product
+    return redirect(url_for('.view'))
+
+
 @producttree.route('/relationship/<int:index>/edit', methods=['GET', 'POST'])
 @document_required
 @producttree_required
--- a/farol/templates/producttree/view_product.j2	Thu Oct 09 14:26:33 2014 +0200
+++ b/farol/templates/producttree/view_product.j2	Thu Oct 09 14:26:59 2014 +0200
@@ -24,7 +24,7 @@
 -#}
 
 {% extends "base.j2" %}
-{% from "macros.j2" import panel %}
+{% from "macros.j2" import panel, delete_button %}
 {% block title %}{{ product._name }}{% endblock %}
 
 {% set active = 'product' %}
@@ -57,4 +57,5 @@
 {% endfor %}
 </ul>
 </div>
+<div class="pull-right">{{ delete_button(url_for('.del_product', productid=product._productid)) }}</div>
 {% endblock %}

http://farol.wald.intevation.org