diff --git a/ippisite/ippidb/migrations/0065_compound_replaced_with.py b/ippisite/ippidb/migrations/0065_compound_replaced_with.py new file mode 100644 index 0000000000000000000000000000000000000000..f4c323218f77c3867815f9019e651c186a924b48 --- /dev/null +++ b/ippisite/ippidb/migrations/0065_compound_replaced_with.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.1 on 2020-09-14 18:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0064_proteindomaincomplex_polymorphic_ctype'), + ] + + operations = [ + migrations.AddField( + model_name='compound', + name='replaced_with', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='ippidb.Compound', verbose_name='Replacement ID'), + ), + ] diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 681c18784b415653205e8e5342372f99390af0fa..181f149b55adb336479967b8c2a980f4e8616a42 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -570,11 +570,13 @@ class CompoundsManager(models.Manager): qs = self.get_queryset() if current_user.is_anonymous: qs = qs.exclude(compoundaction__ppi__contribution__validated=False) + qs = qs.filter(replaced_with__isnull=True) elif not current_user.is_superuser: qs = qs.exclude( Q(compoundaction__ppi__contribution__validated=False), ~Q(compoundaction__ppi__contribution__contributor=current_user), ) + qs = qs.filter(replaced_with__isnull=True) return qs def validated(self): @@ -865,6 +867,14 @@ class Compound(AutoFillableModel): verbose_name="Number of tests available", null=True, blank=True ) + replaced_with = models.ForeignKey( + "self", + verbose_name="Replacement ID", + null=True, + blank=True, + on_delete=models.PROTECT, + ) + class Meta: ordering = ["id"] indexes = [ @@ -1097,7 +1107,9 @@ class Compound(AutoFillableModel): Replace the references to a given compound in the data with references to another new compound. used to deal with duplicates in the database + also delete this object """ + self.replaced_with = replacing_compound for ref in RefCompoundBiblio.objects.filter(compound=self): ref.compound = replacing_compound ref.save() diff --git a/ippisite/ippidb/templates/compound_card.html b/ippisite/ippidb/templates/compound_card.html index eff17990d7d7392829d852b22aa341cff18ee5d2..680c2290d679b8b7491aa9b8be85ee8374ae820d 100644 --- a/ippisite/ippidb/templates/compound_card.html +++ b/ippisite/ippidb/templates/compound_card.html @@ -37,7 +37,9 @@ {% include "compound_smiles_draw.html" with id=compound.id smile=compound.canonical_smile width=250 height=250%} <div style="display: flex; align-items: center;"> - {% if compound.is_validated is False %} + {% if compound.replaced_with is not None %} + <h1 class="page-title-warning" style="margin: 0;">Compound {{ compound.id }} - This compound is replaced with <a href="/compounds/{{ compound.replaced_with.id }}">compound {{ compound.replaced_with.id }}</a> </h1> + {% elif compound.is_validated is False %} <h1 class="page-title-warning" style="margin: 0;">Compound {{ compound.id }} - This compound has not been validated by a curator yet, data might be incomplete or inaccurate</h1> diff --git a/ippisite/ippidb/templates/compound_l_item.html b/ippisite/ippidb/templates/compound_l_item.html index 7f55c823b813cdc19805eeb7dde7e73bcc478d9e..f86f41f1e4fcb890faeee8070e57b6aeda8ef355 100644 --- a/ippisite/ippidb/templates/compound_l_item.html +++ b/ippisite/ippidb/templates/compound_l_item.html @@ -1,8 +1,10 @@ <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"> + <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 %}"> <a href="/compounds/{{ compound.id }}">{% include "compound_smiles_draw.html" with id=compound.id smile=compound.canonical_smile %}</a> - <h2 class="position-absolute" style="top:0.3em; left:0.3em;"><span class="badge badge-light"><a href="/compounds/{{ compound.id }}">{{ compound.id }}</a></span></h2> + <h2 class="position-absolute" style="top:0.3em; left:0.3em;"><span class="badge badge-light"><a href="/compounds/{{ compound.id }}">{{ compound.id }}</a></span>{% if compound.replaced_with is not None %} + <span style="font-size: 26px; color:#fa8005; font-size: 75%;">replaced with <a href="/compounds/{{ compound.replaced_with.id }}">{{ compound.replaced_with.id }}</a></span>{% elif compound.is_validated is False %}<span + style="font-size: 26px; color:#fa8005;">not validated</span>{% endif %}</h2> {% 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 %} diff --git a/ippisite/ippidb/templates/compound_t_list.html b/ippisite/ippidb/templates/compound_t_list.html index 81673f8411144cbb38acf2543a67b823e396d234..98260a99af84388bc13e093649a80daeb5e05193 100644 --- a/ippisite/ippidb/templates/compound_t_list.html +++ b/ippisite/ippidb/templates/compound_t_list.html @@ -28,11 +28,13 @@ </thead> <tbody> {% for compound in compounds %} - <tr> + <tr class="{% if compound.replaced_with or compound.is_validated is False %}bg_warning{% endif %}"> {% if compound.tanimoto != None %} <td title="tanimoto similarity value">{{ compound.tanimoto }}</td> {% endif %} - <td scope="col"><span class="badge badge-light"><a href="/compounds/{{ compound.id }}">{{ compound.id }}</a></span></td> + <td scope="col"><span class="badge badge-light"><a href="/compounds/{{ compound.id }}">{{ compound.id }}</a>{% if compound.replaced_with is not None %} + <span style="font-size: 26px; color:#fa8005; font-size: 75%;">replaced with <a href="/compounds/{{ compound.replaced_with.id }}">{{ compound.replaced_with.id }}</a></span>{% elif compound.is_validated is False %}<span + style="font-size: 26px; color:#fa8005;">not validated</span>{% endif %}</span></td> {% if "canonical_smiles" in fields %} <td scope="col" style="width:150px">{% include "compound_smiles_draw.html" with id=compound.id smile=compound.canonical_smile width="150" height="150"%}</td> {% endif %} diff --git a/ippisite/ippidb/templates/compound_v_item.html b/ippisite/ippidb/templates/compound_v_item.html index 60e175c2094df59331cfccd580d7b8eb092b9018..72d84920ad1bfc72ce275888504dec55017e676a 100644 --- a/ippisite/ippidb/templates/compound_v_item.html +++ b/ippisite/ippidb/templates/compound_v_item.html @@ -1,15 +1,23 @@ <div class="p-2"> - <div class="card border border-info border_card {% if compound.is_validated is False %}bg_warning{% endif %}"> - <a href="/compounds/{{ compound.id }}">{% include "compound_smiles_draw.html" with id=compound.id smile=compound.canonical_smile %}</a> - <h2 class="position-absolute" style="top:0.3em; left:0.3em;"><span class="badge badge-light"><a href="/compounds/{{ compound.id }}">{{ compound.id }}</a></span>{% if compound.is_validated is False %}<span style="font-size: 26px; color:#fa8005;">not validated</span>{% endif %}</h2> + <div class="card border border-info border_card {% if compound.replaced_with or compound.is_validated is False %}bg_warning{% endif %}"> + <a + href="/compounds/{{ compound.id }}">{% include "compound_smiles_draw.html" with id=compound.id smile=compound.canonical_smile %}</a> + <h2 class="position-absolute" style="top:0.3em; left:0.3em;"><span class="badge badge-light"><a + href="/compounds/{{ compound.id }}">{{ compound.id }}</a></span>{% if compound.replaced_with is not None %} + <span style="font-size: 26px; color:#fa8005; font-size: 75%;">replaced with <a href="/compounds/{{ compound.replaced_with.id }}">{{ compound.replaced_with.id }}</a></span>{% elif compound.is_validated is False %}<span + style="font-size: 26px; color:#fa8005;">not validated</span>{% endif %}</h2> {% if compound.tanimoto != None %} - <h2 class="position-absolute" style="top:0.3em; right:0.3em;" title="tanimoto similarity value"><span class="badge badge-dark text-warning">{{ compound.tanimoto }}</span></h2> + <h2 class="position-absolute" style="top:0.3em; right:0.3em;" title="tanimoto similarity value"><span + class="badge badge-dark text-warning">{{ compound.tanimoto }}</span></h2> {% endif %} <div class="card-body desc_card" style="overflow:hidden; word-wrap:break-word;"> - {%if compound.common_name %}<p title="Common name"><span style="font-family:'BrandonGrotesqueBlk';">Common name : </span>{{ compound.common_name }}</p>{%else%}<p></br></p>{% endif %} - <p title="PPI Family"><span style="font-family:'BrandonGrotesqueBlk';">PPI Family : </span>{{ compound.best_activity_ppi_family_name }}</p> - <p title="Molecular Weight"><span style="font-family:'BrandonGrotesqueBlk';">Molecular weight: </span>{{ compound.molecular_weight }} g/mol</p> + {%if compound.common_name %}<p title="Common name"><span style="font-family:'BrandonGrotesqueBlk';">Common + name : </span>{{ compound.common_name }}</p>{%else%}<p></br></p>{% endif %} + <p title="PPI Family"><span style="font-family:'BrandonGrotesqueBlk';">PPI Family : + </span>{{ compound.best_activity_ppi_family_name }}</p> + <p title="Molecular Weight"><span style="font-family:'BrandonGrotesqueBlk';">Molecular weight: + </span>{{ compound.molecular_weight }} g/mol</p> <p style="text-align:right;"><a class="read-more" href="/compounds/{{ compound.id }}">Read more</a></p> </div> </div> -</div> +</div> \ No newline at end of file