Commit 4065f8e6 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

handle "compound replacement" in DB and interface

- replaced compounds can only be viewed by superusers
- and are clearly indicated as such

FIX #241
parent 9b3f63ab
Pipeline #37417 failed with stages
in 13 minutes and 33 seconds
# 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'),
),
]
......@@ -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()
......
......@@ -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>
......
<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 %}
......
......@@ -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 %}
......
<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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment