view farol/templates/producttree/view_product.j2 @ 137:5a44d377aad5

Simplify code, don't use the map filter (Jinja>=2.7)
author Benoît Allard <benoit.allard@greenbone.net>
date Mon, 27 Oct 2014 11:20:06 +0100
parents 1feed9a3156e
children
line wrap: on
line source
{#
# Description:
# Web Template used in Farol Design
#
# Authors:
# BenoƮt Allard <benoit.allard@greenbone.net>
#
# Copyright:
# Copyright (C) 2014 Greenbone Networks GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#}

{% extends "base.j2" %}
{% from "macros.j2" import panel, edit_button, delete_button %}
{% block title %}{{ product._name }}{% endblock %}

{% set active = 'product' %}

{% block content %}
<div class="pull-right">{{ edit_button(url_for('.edit_product', productid=product._productid)) }}</div>
<div class='page-header'>
  <h1>{{ product._name }}{% if product._cpe %} <small>{{ product._cpe }}</small>{% endif %}</h1>
</div>

{% if product.isRelationship() %}
  <p>This product is defined by the following relationship:</p>
  {% set prodref = cvrf.getProductForID(product._parent._productreference) %}
  {% set relatesto = cvrf.getProductForID(product._parent._relatestoproductreference) %}
  <p><a href="{{ url_for('.view_product', productid=prodref._productid) }}">{{ prodref._name }}</a> as <em>{{ product._parent._relationtype | lower }}</em> <a href="{{ url_for('.view_product', productid=relatesto._productid) }}">{{ relatesto._name }}</a><p>
{% elif not product.isRoot() %}
  {% call panel(heading="Tree", title=3, collapsible=False) %}
  {% for type, name in product.getTree() %}
    <ul><li>{{ type }}: <em>{{ name }}</em></li>
    {% if loop.last %}{{ '</ul>' * loop.index }}{% endif %}
  {% endfor %}
  {% endcall %}
{% endif %}

{% call panel(heading="Relationships", title=3, collapsible=False) %}
  <p>This product is part of the following relationships:</p>
  <ul>
  {% for relationship in cvrf._producttree._relationships if product._productid in (relationship._productreference, relationship._relatestoproductreference) %}
    {% set prodref2 = cvrf.getProductForID(relationship._productreference) %}
    {% set relatesto2 = cvrf.getProductForID(relationship._relatestoproductreference) %}
    <li><a href="{{ url_for('.view_product', productid=prodref2._productid) }}">{{ prodref2._name }}</a> as <em>{{ relationship._relationtype | lower }}</em> <a href="{{ url_for('.view_product', productid=relatesto2._productid) }}">{{ relatesto2._name }}</a></li>
  {% else %}
    <li><em>None</em></li>
  {% endfor %}
  </ul>
{% endcall %}

{% call panel(heading="Groups", title=3, collapsible=False) %}
  <p>This product belong to the following groups:</p>
  <ul>
  {% for group in groups %}
    <li>{{ group.getTitle() }}</li>
  {% else %}
    <li><em>None</em></li>
  {% endfor %}
  </ul>
{% endcall %}

{% call panel(heading="Vulnerabilities", title="3", collapsible=False) %}
  <p>The following Vulneralibities are mentionning this product:</p>
  <ul>
    {% for vulnerability in cvrf._vulnerabilities %}
      {%- set elements = vulnerability.mentionsProdId(product._productid) | list %}
      {%- for group in groups %}
        {{- elements.extend(vulnerability.mentionsGroupId(group._groupid) | list) or '' }}
      {%- endfor %}
      {% if elements %}
        <li>
          <a href="{{ url_for('vulnerability.view', ordinal=vulnerability._ordinal) }}">{{ vulnerability.getTitle() }}</a>
          {%- set comma = joiner(', ') %}
          ({% for grouper, list in elements | groupby('NAME') %}{{ comma() -}}
            {{ grouper }}{% if list | length > 1 %} (x{{ list | length }}){% endif %}
          {%- endfor %})
        </li>
      {% endif %}
    {% endfor %}
  </ul>
{% endcall %}
<div class="pull-right">
  {% if cvrf.isProductOrphan(product._productid) %}
    {{ delete_button(url_for('.del_product', productid=product._productid)) }}
  {% else %}
    <p class="text-danger"><small>This product cannot be deleted, as it is referenced in the document</small></p>
  {% endif %}
</div>
{% endblock %}

http://farol.wald.intevation.org