# HG changeset patch # User BenoƮt Allard # Date 1412860590 -7200 # Node ID e02724c84bae4c99a3b36b520ead5c8e210ae52a # Parent 2d41121ec991c8ab9391341dd23c68ec9cb618c1 Add deletion of (orphaned) relationships diff -r 2d41121ec991 -r e02724c84bae farol/producttree.py --- 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//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//edit', methods=['GET', 'POST']) @document_required @producttree_required diff -r 2d41121ec991 -r e02724c84bae farol/templates/producttree/view.j2 --- 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() %} -

{{ cvrf.getProductForID(relationship._productreference)._name }} as {{ relationship._relationtype | lower }} {{ cvrf.getProductForID(relationship._relatestoproductreference)._name }} (edit)

+
{{ cvrf.getProductForID(relationship._productreference)._name }} as {{ relationship._relationtype | lower }} {{ cvrf.getProductForID(relationship._relatestoproductreference)._name }} (edit){% if relationship.isOrphaned() %}{{ delete_button(url_for('.del_relationship', index=loop.index0)) }}{% endif %}
{% if relationship._product %}

{{ relationship._product._name }}

{% endif %} {% if relationship.isOrphaned() %}

This relationship is orphaned. A product should be created as child of this one.

diff -r 2d41121ec991 -r e02724c84bae farol/templates/producttree/view_product.j2 --- 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 %} +

This product belong to the following groups:

    {% for group in cvrf._producttree._groups if product._productid in group._productids %}
  • {{ group.getTitle() }}
  • +{% else %} +
  • None
  • {% endfor %}