From 8e85d2bb41046ec9b8564f052f150abfcb03f043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20M=C3=A9nager?= <herve.menager@pasteur.fr> Date: Tue, 22 Dec 2020 11:08:07 +0100 Subject: [PATCH] correct sameAs syntax in compound cards FIX #250 --- ippisite/ippidb/models.py | 15 +++++++++++++++ ippisite/ippidb/templates/compound_card.html | 16 ++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 6b285505..20cfd37b 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -1150,6 +1150,21 @@ class Compound(AutoFillableModel): else None ) + @property + def sameas_urls(self): + urls = [] + if self.pubchem_id: + urls.append(self.pubchem_url) + if self.chembl_id: + urls.append(self.chembl_url) + if self.chemspider_id: + urls.append(self.chemspider_url) + if self.ligand_id: + urls.append(self.pdbligand_url) + if self.drugbank_id: + urls.append(self.drugbank_url) + return urls + def clean(self): """ Perform additional checks: diff --git a/ippisite/ippidb/templates/compound_card.html b/ippisite/ippidb/templates/compound_card.html index ba4c780e..f2a4df83 100644 --- a/ippisite/ippidb/templates/compound_card.html +++ b/ippisite/ippidb/templates/compound_card.html @@ -572,20 +572,8 @@ "smiles": [ "{{ compound.canonical_smile }}" ], -{% if compound.pubchem_id %} -"sameAs": "{{ compound.pubchem_url }}", -{% endif %} -{% if compound.chembl_id %} -"sameAs": "{{ compound.chembl_url }}", -{% endif %} -{% if compound.chemspider_id %} -"sameAs": "{{ compound.chemspider_url }}", -{% endif %} -{% if compound.ligand_id %} -"sameAs": "{{ compound.pdbligand_url }}", -{% endif %} -{% if compound.drugbank_id %} -"sameAs": "{{ compound.drugbank_url }}", +{% if compound.sameas_urls %} +"sameAs": {{ compound.sameas_urls|safe }}, {% endif %} "@context": "http://schema.org" } -- GitLab