Commit f2d73151 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

Merge branch 'master' into 'release'

prepare for v1.0.7 continued part 2

See merge request !27
parents 22387e1a 9bbf34f2
Pipeline #46773 canceled with stages
......@@ -1089,7 +1089,7 @@ class Compound(AutoFillableModel):
"""
String representation
"""
return "Compound #{}".format(self.id)
return "iPPI-DB Compound #{}".format(self.id)
def get_absolute_url(self):
"""
......@@ -1165,6 +1165,29 @@ class Compound(AutoFillableModel):
urls.append(self.drugbank_url)
return urls
def get_bioschemas(self, request):
json_data = {"@type": "MolecularEntity", "@context": "http://schema.org"}
json_data["name"] = str(self)
if self.pk is not None:
json_data["url"] = request.build_absolute_uri(self.get_absolute_url())
if self.inchi is not None:
json_data["inChI"] = self.inchi
if self.iupac_name != "":
json_data["iupacName"] = self.iupac_name
if self.molecular_weight is not None:
json_data["molecularWeight"] = self.molecular_weight
if self.inchikey is not None:
json_data["inChIKey"] = self.inchikey
if self.chembl_id is not None:
json_data[
"image"
] = f"https://www.ebi.ac.uk/chembl/api/data/image/{ self.chembl_id }.svg"
if self.canonical_smile is not None:
json_data["smiles"] = self.canonical_smile
if len(self.sameas_urls) > 0:
json_data["sameAs"] = self.sameas_urls
return json_data
def clean(self):
"""
Perform additional checks:
......@@ -1644,7 +1667,10 @@ class ContributionManager(models.Manager):
if current_user.is_anonymous:
qs = qs.exclude(validated=False)
elif not current_user.is_superuser:
qs = qs.exclude(Q(validated=False), ~Q(contributor=current_user),)
qs = qs.exclude(
Q(validated=False),
~Q(contributor=current_user),
)
return qs
def validated(self):
......@@ -1713,7 +1739,10 @@ def update_compound_cached_properties(compounds_queryset=None):
le=Subquery(
compounds_queryset.filter(id=OuterRef("id"))
.annotate(
_le=Cast(1.37 * F("best_activity") / F("nb_atom_non_h"), FloatField(),)
_le=Cast(
1.37 * F("best_activity") / F("nb_atom_non_h"),
FloatField(),
)
)
.values("_le")[:1]
),
......
......@@ -557,42 +557,7 @@
</div>
</div>
<script id='JSON_LD' type="application/ld+json">
{
"url": "{{ request.build_absolute_uri }}",
{% if compound.inchi %}
"inChI": "{{ compound.inchi }}",
{% endif %}
{% if compound.iupac_name %}
"name": "{{ compound.iupac_name }}",
{% endif %}
{% if compound.iupac_name %}
"iupacName": "{{ compound.iupac_name }}",
{% endif %}
{% if compound.molecular_weight %}
"molecularWeight": {{ compound.molecular_weight }},
{% endif %}
"identifier": "{{ compound.id }}",
{% if compound.inchikey %}
"inChIKey": "{{ compound.inchikey }}",
{% endif %}
"@type": "MolecularEntity",
{% if compound.chembl_id %}
"image": "https://www.ebi.ac.uk/chembl/api/data/image/{{ compound.chembl_id }}.svg",
{% endif %}
{% if compound.canonical_smile %}
"smiles": [
"{{ compound.canonical_smile|escapejs }}"
],
{% endif %}
{% if compound.sameas_urls %}
"sameAs": {{ compound.sameas_urls|safe }},
{% endif %}
"@context": "http://schema.org"
}
</script>
{{ bioschemas_data|json_script:compound }}
<script>
var showTab = function (hash) {
window.location.hash = hash;
......
......@@ -771,6 +771,7 @@ class CompoundDetailView(DetailView):
pca_biplot = {"data": [], "correlation_circle": ""}
context["pca_biplot_data"] = pca_biplot["data"]
context["pca_biplot_cc"] = pca_biplot["correlation_circle"]
context["bioschemas_data"] = self.object.get_bioschemas(self.request)
return context
......
Markdown is supported
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