Skip to content
Snippets Groups Projects
Commit 24ca2db5 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

fix bioschemas syntax for compound card

we now generate all of bioschemas json from the model.
also related to #267 and #268.
parent 27af1fc2
No related branches found
No related tags found
1 merge request!27prepare for v1.0.7 continued part 2
Pipeline #44064 failed
......@@ -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,30 @@ 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:
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment