From 3cc5752b925259d73c8624c4371412a7ff92b101 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20M=C3=A9nager?= <herve.menager@pasteur.fr>
Date: Wed, 18 Nov 2020 16:09:21 +0100
Subject: [PATCH] add icons for physicochemical rules compliance in compounds
 list

as requested in #251
---
 ippisite/ippidb/templates/compound_l_item.html |  7 +++++++
 ippisite/ippidb/templatetags/customtags.py     | 13 +++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/ippisite/ippidb/templates/compound_l_item.html b/ippisite/ippidb/templates/compound_l_item.html
index b59d9cc2..f1341792 100644
--- a/ippisite/ippidb/templates/compound_l_item.html
+++ b/ippisite/ippidb/templates/compound_l_item.html
@@ -1,3 +1,5 @@
+{% load customtags %}
+
 <div class="row m-2 border border-info bg-light border_card" style="box-shadow: 0 3px 5px 0 rgba(0, 0, 0, 0.2);">
   {%if show_detail != True %}
   <div class="col-sm-3 border-info d-flex justify-content-center align-content-center {% if compound.replaced_with or compound.is_validated is False %}bg_warning{% endif %}">
@@ -8,6 +10,11 @@
     {% if compound.tanimoto != None %}
     <h2 class="position-absolute" style="top:0.3em; right:0.3em;" title="tanimoto similarity value"><span class="badge badge-light text-warning">{{ compound.tanimoto }}</span></h2>
     {% endif %}
+    <h2 class="position-absolute" style="top:270px; left:0.3em;"><span class="badge badge-light">
+      {% rule_status_icon compound.lipinsky "Lipinski's RO5" %}
+      {% rule_status_icon compound.veber "Veber" %}
+      {% rule_status_icon compound.pfizer "Pfizer" %}
+    </h2>
   </div>
   {% endif %}
   <div class="{%if show_detail != True %}col-sm-9{% else %}col-sm-12{% endif %}">
diff --git a/ippisite/ippidb/templatetags/customtags.py b/ippisite/ippidb/templatetags/customtags.py
index 6c1b2c14..501905c8 100644
--- a/ippisite/ippidb/templatetags/customtags.py
+++ b/ippisite/ippidb/templatetags/customtags.py
@@ -28,6 +28,19 @@ def status_class(value):
     else:
         return "table-secondary"
 
+@register.simple_tag
+def rule_status_icon(value, title):
+    if value is True:
+        class_suffix = 'success'
+        icon_suffix  = 'check'
+    elif value is False:
+        class_suffix = 'danger'
+        icon_suffix = 'times'
+    else:
+        class_suffix = 'secondary'
+        class_suffix = 'question'
+    return mark_safe(f'<i class="fas fa-{icon_suffix} text-{class_suffix}" title="{title}: failed"></i>')
+
 
 @register.filter
 def bootstrap(object):
-- 
GitLab