From 3e23f63ce2d7d46391ef96077e43db16660fbe71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Finn=20=C3=85rup=20Nielsen?= Date: Fri, 7 Jun 2024 19:16:47 +0200 Subject: [PATCH 1/9] Fix #2429 config module The setup and reading of the configuration is handle by a separate module. --- scholia/config.py | 46 ++++++++++++++++++++++++++++++++++++++++ scholia/network.py | 4 +++- scholia/query.py | 7 ++++-- scholia/rss.py | 4 +++- scholia/scrape/ceurws.py | 9 +++++--- scholia/scrape/nips.py | 14 +++++++----- scholia/scrape/ojs.py | 9 +++++--- scholia/text.py | 4 +++- scholia/wikipedia.py | 5 ++++- 9 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 scholia/config.py diff --git a/scholia/config.py b/scholia/config.py new file mode 100644 index 000000000..d3c00e2c3 --- /dev/null +++ b/scholia/config.py @@ -0,0 +1,46 @@ +"""config. + +Usage: + scholia.config + +""" + +import configparser + +from io import StringIO + +from os.path import exists, expanduser + + +CONFIG_FILENAMES = [ + 'scholia.ini', + '~/etc/scholia.ini', + '~/scholia.ini'] + +DEFAULTS = """ +[query-server] +sparql_endpoint = https://query.wikidata.org/sparql + +[requests] +user_agent = Scholia + +""" + + +config = configparser.ConfigParser() + +config.read_file(StringIO(DEFAULTS)) + +for filename in CONFIG_FILENAMES: + full_filename = expanduser(filename) + if exists(full_filename): + config.read(full_filename) + break + + +if __name__ == '__main__': + for section in config.sections(): + print(f"[{section}]") + for key in config[section]: + print(f"{key} = {config[section].get(key)}") + print() diff --git a/scholia/network.py b/scholia/network.py index 22a13acc3..ef78257f9 100644 --- a/scholia/network.py +++ b/scholia/network.py @@ -7,11 +7,13 @@ from collections import OrderedDict -from .query import SPARQL_ENDPOINT +from .config import config import requests +SPARQL_ENDPOINT = config['query-server'].get('sparql_endpoint') + EXAMPLE_SPARQL_QUERY = """ SELECT ?item1 ?item1Label ?item2 ?item2Label ?weight WITH { diff --git a/scholia/query.py b/scholia/query.py index 898c27dbb..cfdecef18 100644 --- a/scholia/query.py +++ b/scholia/query.py @@ -59,9 +59,12 @@ from six import u -SPARQL_ENDPOINT = "https://query.wikidata.org/sparql" +from .config import config -USER_AGENT = 'Scholia' + +SPARQL_ENDPOINT = config['query-server'].get('sparql_endpoint') + +USER_AGENT = config['requests'].get('user_agent') HEADERS = {'User-Agent': USER_AGENT} diff --git a/scholia/rss.py b/scholia/rss.py index 5dee65698..7705cc090 100644 --- a/scholia/rss.py +++ b/scholia/rss.py @@ -49,7 +49,9 @@ from six import u -from .query import SPARQL_ENDPOINT +from .config import config + +SPARQL_ENDPOINT = config['query-server'].get('sparql_endpoint') WORK_ITEM_RSS = u(""" diff --git a/scholia/scrape/ceurws.py b/scholia/scrape/ceurws.py index cbd9fd188..1eeb3b0ec 100644 --- a/scholia/scrape/ceurws.py +++ b/scholia/scrape/ceurws.py @@ -29,12 +29,15 @@ import requests +from ..config import config from ..qs import paper_to_quickstatements, proceedings_to_quickstatements -from ..query import iso639_to_q, SPARQL_ENDPOINT as WDQS_URL +from ..query import iso639_to_q from ..utils import escape_string, pages_to_number_of_pages -USER_AGENT = 'Scholia' +SPARQL_ENDPOINT = config['query-server'].get('sparql_endpoint') + +USER_AGENT = config['requests'].get('user_agent') HEADERS = {'User-Agent': USER_AGENT} @@ -264,7 +267,7 @@ def paper_to_q(paper): query = SHORT_TITLED_PAPER_TO_Q_QUERY.format( url=url) - response = requests.get(WDQS_URL, + response = requests.get(SPARQL_ENDPOINT, params={'query': query, 'format': 'json'}, headers=HEADERS) if not response.ok: diff --git a/scholia/scrape/nips.py b/scholia/scrape/nips.py index 229cc9421..8de35f726 100644 --- a/scholia/scrape/nips.py +++ b/scholia/scrape/nips.py @@ -47,9 +47,14 @@ import requests +from ..config import config from ..qs import paper_to_quickstatements from ..utils import escape_string -from ..query import SPARQL_ENDPOINT as WDQS_URL + + +SPARQL_ENDPOINT = config['query-server'].get('sparql_endpoint') + +USER_AGENT = config['requests'].get('user_agent') PAPER_TO_Q_QUERY = u(""" SELECT ?paper WHERE {{ @@ -63,7 +68,6 @@ URL_BASE = "https://papers.nips.cc" -USER_AGENT = "Scholia" # Year should be the nominal year, - not the year of publication YEAR_TO_Q = { @@ -146,9 +150,9 @@ def paper_to_q(paper): label=title, title=title, url=paper['url'], full_text_url=paper['full_text_url']) - response = requests.get( - WDQS_URL, params={'query': query, 'format': 'json'}, - headers={'User-Agent': USER_AGENT}) + response = requests.get(SPARQL_ENDPOINT, + params={'query': query, 'format': 'json'}, + headers={'User-Agent': USER_AGENT}) if not response.ok: raise Exception("Wikidata API response error: {}".format( response.status_code)) diff --git a/scholia/scrape/ojs.py b/scholia/scrape/ojs.py index 4b5ea8944..e31911da0 100644 --- a/scholia/scrape/ojs.py +++ b/scholia/scrape/ojs.py @@ -31,12 +31,15 @@ import requests +from ..config import config from ..qs import paper_to_quickstatements -from ..query import iso639_to_q, issn_to_qs, SPARQL_ENDPOINT as WDQS_URL +from ..query import iso639_to_q, issn_to_qs from ..utils import escape_string, pages_to_number_of_pages -USER_AGENT = 'Scholia' +SPARQL_ENDPOINT = config['query-server'].get('sparql_endpoint') + +USER_AGENT = config['requests'].get('user_agent') HEADERS = {'User-Agent': USER_AGENT} @@ -173,7 +176,7 @@ def paper_to_q(paper): query = SHORT_TITLED_PAPER_TO_Q_QUERY.format( url=paper['url']) - response = requests.get(WDQS_URL, + response = requests.get(SPARQL_ENDPOINT, params={'query': query, 'format': 'json'}, headers=HEADERS) data = response.json()['results']['bindings'] diff --git a/scholia/text.py b/scholia/text.py index 659257be5..aecf4b5a4 100644 --- a/scholia/text.py +++ b/scholia/text.py @@ -30,7 +30,7 @@ from six.moves import cPickle as pickle -from .query import SPARQL_ENDPOINT +from .config import config import re @@ -39,6 +39,8 @@ import requests +SPARQL_ENDPOINT = config['query-server'].get('sparql_endpoint') + TOPIC_LABELS_SPARQL = """ SELECT ?topic ?topic_label WITH { diff --git a/scholia/wikipedia.py b/scholia/wikipedia.py index 6f77dff75..a0386bf1d 100644 --- a/scholia/wikipedia.py +++ b/scholia/wikipedia.py @@ -29,7 +29,10 @@ from six import b, u -from .query import SPARQL_ENDPOINT +from .config import config + + +SPARQL_ENDPOINT = config['query-server'].get('sparql_endpoint') BIBLIOGRAPHY_SPARQL_QUERY = """ From 43d97421a9fe8cb2b23283ecb5b49c03c43871db Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 8 Jun 2024 12:16:20 +0200 Subject: [PATCH 2/9] Propagate the SPARQL endpoint URL to JavaScript too --- scholia/app/static/scholia.js | 31 ++++++++++++++++++++++++++----- scholia/app/templates/base.html | 6 ++++-- scholia/app/views.py | 3 ++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/scholia/app/static/scholia.js b/scholia/app/static/scholia.js index 07fac0772..5c38912ca 100644 --- a/scholia/app/static/scholia.js +++ b/scholia/app/static/scholia.js @@ -208,8 +208,7 @@ function addReloadButton(element, callback) { } } -function sparqlToResponse(sparql, doneCallback) { - var endpointUrl = "https://query.wikidata.org/bigdata/namespace/wdq/sparql"; +function sparqlToResponse(endpointUrl, sparql, doneCallback) { var settings = { headers: { Accept: "application/sparql-results+json" }, data: { query: sparql }, @@ -218,6 +217,14 @@ function sparqlToResponse(sparql, doneCallback) { } +function sparqlToResponse(sparql, doneCallback) { + return sparqlToResponse( + "https://query.wikidata.org/bigdata/namespace/wdq/sparql", + sparql, doneCallback + ); +} + + function sparqlDataToSimpleData(response) { // Convert long JSON data from from SPARQL endpoint to short form let data = response.results.bindings; @@ -235,10 +242,17 @@ function sparqlDataToSimpleData(response) { function sparqlToDataTablePost(sparql, element, filename, options = {}) { + sparqlToDataTablePost( + "https://query.wikidata.org/sparql", sparql, element, filename, options + ); +} + + +function sparqlToDataTablePost(url, sparql, element, filename, options = {}) { // Options: paging= + if (!url) url = "https://query.wikidata.org/sparql"; var paging = (typeof options.paging === 'undefined') ? true : options.paging; var sDom = (typeof options.sDom === 'undefined') ? 'lfrtip' : options.sDom; - var url = "https://query.wikidata.org/sparql"; $(element).html("
"); @@ -287,11 +301,18 @@ function sparqlToDataTablePost(sparql, element, filename, options = {}) { function sparqlToDataTable(sparql, element, filename, options = {}) { + sparqlToDataTablePost( + "https://query.wikidata.org/sparql", sparql, element, filename, options + ); +} + + +function sparqlToDataTable(url, sparql, element, filename, options = {}) { // Options: paging=true + if (!url) url = "https://query.wikidata.org/sparql"; var paging = (typeof options.paging === 'undefined') ? true : options.paging; var sDom = (typeof options.sDom === 'undefined') ? 'lfrtip' : options.sDom; - var url = "https://query.wikidata.org/sparql?query=" + - encodeURIComponent(sparql) + '&format=json'; + var url = url + "?query=" + encodeURIComponent(sparql) + '&format=json'; const datatableFooter = ' Date: Sat, 8 Jun 2024 12:59:11 +0200 Subject: [PATCH 3/9] More passing around the configurable SPARQL endpoint --- scholia/app/views.py | 195 ++++++++++++++++++++++++++++--------------- 1 file changed, 130 insertions(+), 65 deletions(-) diff --git a/scholia/app/views.py b/scholia/app/views.py index 80155100b..a0cacdff0 100644 --- a/scholia/app/views.py +++ b/scholia/app/views.py @@ -110,7 +110,8 @@ def index_statistics(): Rederende HTML for main statistics page. """ - return render_template('index-statistics.html', sparql_endpoint=config['query-server'].get('sparql_endpoint')) + ep = config['query-server'].get('sparql_endpoint') + return render_template('index-statistics.html', sparql_endpoint=ep) @main.route("/" + l_pattern) @@ -387,6 +388,7 @@ def show_author(q): Rendered HTML. """ + ep = config['query-server'].get('sparql_endpoint') entities = wb_get_entities([q]) name = entity_to_name(entities[q]) if name: @@ -394,7 +396,7 @@ def show_author(q): else: first_initial, last_name = '', '' return render_template('author.html', q=q, first_initial=first_initial, - last_name=last_name) + last_name=last_name, sparql_endpoint=ep)) @main.route('/author/' + q_pattern + '/latest-works/rss') @@ -429,7 +431,8 @@ def show_author_index(): Rendered index page for author view. """ - return render_template('author-index.html') + ep = config['query-server'].get('sparql_endpoint') + return render_template('author-index.html', sparql_endpoint=ep)) @main.route('/author/random') @@ -463,7 +466,8 @@ def show_author_use(q1, q2): Rendered HTML for a specific author and use. """ - return render_template('author-use.html', q1=q1, q2=q2, q=q1) + ep = config['query-server'].get('sparql_endpoint') + return render_template('author-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) @main.route('/authors/' + qs_pattern) @@ -490,7 +494,8 @@ def show_authors(qs): if len(qs) == 1: return redirect(url_for('app.show_author', q=qs[0]), code=301) else: - return render_template('authors.html', qs=qs) + ep = config['query-server'].get('sparql_endpoint') + return render_template('authors.html', qs=qs, sparql_endpoint=ep) @main.route('/award/' + q_pattern) @@ -508,7 +513,8 @@ def show_award(q): Rendered HTML. """ - return render_template('award.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('award.html', q=q, sparql_endpoint=ep) @main.route('/award/') @@ -521,7 +527,8 @@ def show_award_index(): Rendered index page for award view. """ - return render_template('award-index.html') + ep = config['query-server'].get('sparql_endpoint') + return render_template('award-index.html', sparql_endpoint=ep) @main.route('/cas/') @@ -633,7 +640,8 @@ def show_catalogue(q): Rendered HTML page. """ - return render_template('catalogue.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('catalogue.html', q=q, sparql_endpoint=ep) @main.route('/catalogue/') @@ -664,7 +672,8 @@ def show_dataset(q): Rendered HTML page. """ - return render_template('dataset.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('dataset.html', q=q, sparql_endpoint=ep) @main.route('/dataset/') @@ -695,7 +704,8 @@ def show_dataset_export(q): Rendered HTML. """ - return render_template('dataset-export.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('dataset-export.html', q=q, sparql_endpoint=ep) @main.route('/clinical-trial/') @@ -726,7 +736,8 @@ def show_clinical_trial(q): Rendered HTML for a specific clinical trial. """ - return render_template('clinical-trial.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('clinical-trial.html', q=q, sparql_endpoint=ep) @main.route('/countries/' + qs_pattern) @@ -745,7 +756,8 @@ def show_countries(qs): """ qs = Q_PATTERN.findall(qs) - return render_template('countries.html', qs=qs) + ep = config['query-server'].get('sparql_endpoint') + return render_template('countries.html', qs=qs, sparql_endpoint=ep) @main.route('/country/') @@ -776,7 +788,8 @@ def show_country(q): Rendered HTML for a specific country. """ - return render_template('country.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('country.html', q=q, sparql_endpoint=ep) @main.route('/country/' + q1_pattern + '/topic/' + q2_pattern) @@ -796,7 +809,8 @@ def show_country_topic(q1, q2): Rendered HTML for a specific country and topic. """ - return render_template('country-topic.html', q1=q1, q2=q2, q=q1) + ep = config['query-server'].get('sparql_endpoint') + return render_template('country-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) @main.route('/disease/' + q_pattern) @@ -814,7 +828,8 @@ def show_disease(q): Rendered HTML. """ - return render_template('disease.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('disease.html', q=q, sparql_endpoint=ep) @main.route('/disease/') @@ -845,7 +860,8 @@ def redirect_doi(doi): if len(qs) > 0: q = qs[0] return redirect(url_for('app.show_work', q=q), code=302) - return render_template('404-doi.html', doi=doi) + ep = config['query-server'].get('sparql_endpoint') + return render_template('404-doi.html', doi=doi, sparql_endpoint=ep) @main.route('/doi-prefix/') @@ -863,7 +879,8 @@ def redirect_doi_prefix(doi): if len(qs) > 0: q = qs[0] return redirect(url_for('app.show_publisher', q=q), code=302) - return render_template('404.html', doi=doi) + ep = config['query-server'].get('sparql_endpoint') + return render_template('404.html', doi=doi, sparql_endpoint=ep) @main.route('/event/' + q_pattern) @@ -881,7 +898,8 @@ def show_event(q): Rendered HTML. """ - return render_template('event.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('event.html', q=q, sparql_endpoint=ep) @main.route('/event/') @@ -912,7 +930,8 @@ def show_event_series(q): Rendered HTML. """ - return render_template('event-series.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('event-series.html', q=q, sparql_endpoint=ep) @main.route('/event-series/') @@ -1006,7 +1025,8 @@ def redirect_inchikey(inchikey): if len(qs) > 0: q = qs[0] return redirect(url_for('app.show_chemical', q=q), code=302) - return render_template('404-chemical.html', inchikey=inchikey) + ep = config['query-server'].get('sparql_endpoint') + return render_template('404-chemical.html', inchikey=inchikey, sparql_endpoint=ep) @main.route('/issn/') @@ -1041,7 +1061,8 @@ def show_language(q): Rendered HTML for a specific language. """ - return render_template('language.html', q=q, datetime=datetime) + ep = config['query-server'].get('sparql_endpoint') + return render_template('language.html', q=q, datetime=datetime, sparql_endpoint=ep) @main.route('/language') @@ -1085,7 +1106,8 @@ def show_lexeme(lexeme): Rendered HTML for a specific lexeme. """ - return render_template('lexeme.html', lexeme=lexeme) + ep = config['query-server'].get('sparql_endpoint') + return render_template('lexeme.html', lexeme=lexeme, sparql_endpoint=ep) @main.route('/license/' + q_pattern) @@ -1103,7 +1125,8 @@ def show_license(q): Rendered HTML for a specific license. """ - return render_template('license.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('license.html', q=q, sparql_endpoint=ep) @main.route('/license/') @@ -1147,7 +1170,8 @@ def show_location(q): Rendered HTML for a specific location. """ - return render_template('location.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('location.html', q=q, sparql_endpoint=ep) @main.route('/location/' + q1_pattern + '/topic/' + q2_pattern) @@ -1167,7 +1191,8 @@ def show_location_topic(q1, q2): Rendered HTML for a specific location and topic. """ - return render_template('location-topic.html', q1=q1, q2=q2, q=q1) + ep = config['query-server'].get('sparql_endpoint') + return render_template('location-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) @main.route('/mesh/') @@ -1392,7 +1417,8 @@ def show_ontology(q): Rendered HTML. """ - return render_template('ontology.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('ontology.html', q=q, sparql_endpoint=ep) @main.route('/organization/' + q_pattern) @@ -1410,7 +1436,8 @@ def show_organization(q): Rendered HTML. """ - return render_template('organization.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('organization.html', q=q, sparql_endpoint=ep) @main.route('/organization/') @@ -1465,7 +1492,8 @@ def show_organization_topic(q1, q2): Rendered HTML for a specific organization and topic. """ - return render_template('organization-topic.html', q1=q1, q2=q2, q=q1) + ep = config['query-server'].get('sparql_endpoint') + return render_template('organization-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) @main.route('/organization/' + q1_pattern + '/use/' + q2_pattern) @@ -1485,7 +1513,8 @@ def show_organization_use(q1, q2): Rendered HTML for a specific organization and use. """ - return render_template('organization-use.html', q1=q1, q2=q2, q=q1) + ep = config['query-server'].get('sparql_endpoint') + return render_template('organization-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) @main.route('/organizations/' + qs_pattern) @@ -1504,7 +1533,8 @@ def show_organizations(qs): """ qs = Q_PATTERN.findall(qs) - return render_template('organizations.html', qs=qs) + ep = config['query-server'].get('sparql_endpoint') + return render_template('organizations.html', qs=qs, sparql_endpoint=ep) @main.route('/printer/' + q_pattern) @@ -1522,7 +1552,8 @@ def show_printer(q): Rendered HTML. """ - return render_template('printer.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('printer.html', q=q, sparql_endpoint=ep) @main.route('/printer/') @@ -1553,7 +1584,8 @@ def show_protein(q): Rendered HTML. """ - return render_template('protein.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('protein.html', q=q, sparql_endpoint=ep) @main.route('/protein/') @@ -1584,7 +1616,8 @@ def show_project(q): Rendered HTML. """ - return render_template('project.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('project.html', q=q, sparql_endpoint=ep) @main.route('/project/') @@ -1659,7 +1692,8 @@ def show_gene(q): Rendered HTML. """ - return render_template('gene.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('gene.html', q=q, sparql_endpoint=ep) @main.route('/gene/') @@ -1690,6 +1724,7 @@ def show_taxon(q): Rendered HTML. """ + ep = config['query-server'].get('sparql_endpoint') return render_template('taxon.html', q=q) @@ -1728,9 +1763,10 @@ def show_q_to_bibliography_templates(): wikitext = q_to_bibliography_templates(q) + ep = config['query-server'].get('sparql_endpoint') return render_template('q-to-bibliography-templates.html', q=q, - wikitext=wikitext) + wikitext=wikitext, sparql_endpoint=ep) @main.route('/software/' + q_pattern) @@ -1748,7 +1784,8 @@ def show_software(q): Rendered HTML. """ - return render_template('software.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('software.html', q=q, sparql_endpoint=ep) @main.route('/software/') @@ -1779,7 +1816,8 @@ def show_software_export(q): Rendered HTML. """ - return render_template('software-export.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('software-export.html', q=q, sparql_endpoint=ep) @main.route('/text-to-topics', methods=['POST', 'GET']) @@ -1830,7 +1868,8 @@ def show_topic(q): Rendered HTML. """ - return render_template('topic.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('topic.html', q=q, sparql_endpoint=ep) @main.route('/topic/' + q_pattern + '/latest-works/rss') @@ -1885,7 +1924,8 @@ def show_topic_use(q1, q2): Rendered HTML for a specific topic and use. """ - return render_template('topic-use.html', q1=q1, q2=q2, q=q1) + ep = config['query-server'].get('sparql_endpoint') + return render_template('topic-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) @main.route('/topics/' + qs_pattern) @@ -1912,7 +1952,8 @@ def show_topics(qs): if len(qs) == 1: return redirect(url_for('app.show_topic', q=qs[0]), code=301) else: - return render_template('topics.html', qs=qs) + ep = config['query-server'].get('sparql_endpoint') + return render_template('topics.html', qs=qs, sparql_endpoint=ep) @main.route('/podcast/' + q_pattern) @@ -1930,8 +1971,9 @@ def show_podcast(q): Rendered HTML. """ + ep = config['query-server'].get('sparql_endpoint') return render_template( - 'podcast.html', q=q) + 'podcast.html', q=q, sparql_endpoint=ep) @main.route('/podcast-season/' + q_pattern) @@ -1949,8 +1991,9 @@ def show_podcast_season(q): Rendered HTML. """ + ep = config['query-server'].get('sparql_endpoint') return render_template( - 'podcast-season.html', q=q) + 'podcast-season.html', q=q, sparql_endpoint=ep) @main.route('/podcast-episode/' + q_pattern) @@ -1968,8 +2011,9 @@ def show_podcast_episode(q): Rendered HTML. """ + ep = config['query-server'].get('sparql_endpoint') return render_template( - 'podcast-episode.html', q=q) + 'podcast-episode.html', q=q, sparql_endpoint=ep) @main.route('/podcast/random') @@ -1996,7 +2040,8 @@ def show_podcast_in_language(q): Redirect """ - return render_template('podcast-language.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('podcast-language.html', q=q, sparql_endpoint=ep) @main.route('/podcast/') @@ -2029,9 +2074,10 @@ def show_chemical(q): """ entities = wb_get_entities([q]) smiles = entity_to_smiles(entities[q]) + ep = config['query-server'].get('sparql_endpoint') return render_template( 'chemical.html', - q=q, + q=q, sparql_endpoint=ep, smiles=smiles, third_parties_enabled=current_app.third_parties_enabled) @@ -2078,7 +2124,8 @@ def show_chemical_element(q): Rendered HTML. """ - return render_template('chemical-element.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('chemical-element.html', q=q, sparql_endpoint=ep) @main.route('/chemical-element/') @@ -2111,9 +2158,10 @@ def show_chemical_class(q): """ entities = wb_get_entities([q]) smiles = entity_to_smiles(entities[q]) + ep = config['query-server'].get('sparql_endpoint') return render_template( 'chemical-class.html', - q=q, + q=q, sparql_endpoint=ep, smiles=smiles, third_parties_enabled=current_app.third_parties_enabled) @@ -2166,7 +2214,8 @@ def show_venue(q): Rendered HTML page. """ - return render_template('venue.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('venue.html', q=q, sparql_endpoint=ep) @main.route('/venue/' + q_pattern + '/cito') @@ -2204,7 +2253,8 @@ def show_venue_use(q1, q2): Rendered HTML for a specific venue and use. """ - return render_template('venue-use.html', q1=q1, q2=q2, q=q1) + ep = config['query-server'].get('sparql_endpoint') + return render_template('venue-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) @main.route('/work/' + q_pattern + '/cito') @@ -2242,7 +2292,8 @@ def show_work_cito_intention(q, q2): Rendered HTML. """ - return render_template('work-cito-intention.html', q=q, q2=q2) + ep = config['query-server'].get('sparql_endpoint') + return render_template('work-cito-intention.html', q=q, q2=q2, sparql_endpoint=ep) @main.route('/work/' + q_pattern + '/export') @@ -2260,7 +2311,8 @@ def show_work_export(q): Rendered HTML. """ - return render_template('work-export.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('work-export.html', q=q, sparql_endpoint=ep) @main.route('/work/random') @@ -2292,7 +2344,8 @@ def show_cito(q): Rendered HTML. """ - return render_template('cito.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('cito.html', q=q, sparql_endpoint=ep) @main.route('/cito/') @@ -2363,7 +2416,8 @@ def show_venues(qs): """ qs = Q_PATTERN.findall(qs) - return render_template('venues.html', qs=qs) + ep = config['query-server'].get('sparql_endpoint') + return render_template('venues.html', qs=qs, sparql_endpoint=ep) @main.route('/series/' + q_pattern) @@ -2381,7 +2435,8 @@ def show_series(q): Rendered HTML for specific series. """ - return render_template('series.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('series.html', q=q, sparql_endpoint=ep) @main.route('/series/') @@ -2412,7 +2467,8 @@ def show_complex(q): Rendered HTML. """ - return render_template('complex.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('complex.html', q=q, sparql_endpoint=ep) @main.route('/complex/') @@ -2443,7 +2499,8 @@ def show_pathway(q): Rendered HTML. """ - return render_template('pathway.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('pathway.html', q=q, sparql_endpoint=ep) @main.route('/pathway/') @@ -2469,7 +2526,8 @@ def show_publisher(q): Rendered HTML page for specific publisher. """ - return render_template('publisher.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('publisher.html', q=q, sparql_endpoint=ep) @main.route('/publisher/') @@ -2535,7 +2593,8 @@ def show_sponsor(q): Rendered HTML page for specific sponsor. """ - return render_template('sponsor.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('sponsor.html', q=q, sparql_endpoint=ep) @main.route('/sponsor/') @@ -2588,7 +2647,8 @@ def show_use(q): Rendered HTML. """ - return render_template('use.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('use.html', q=q, sparql_endpoint=ep) @main.route('/use/') @@ -2628,7 +2688,8 @@ def show_uses(qs): if len(qs) == 1: return redirect(url_for('app.show_use', q=qs[0]), code=301) else: - return render_template('uses.html', qs=qs) + ep = config['query-server'].get('sparql_endpoint') + return render_template('uses.html', qs=qs, sparql_endpoint=ep) @main.route('/work/' + q_pattern) @@ -2650,7 +2711,8 @@ def show_work(q): dois = q_to_dois(q) except Exception: dois = [] - return render_template('work.html', q=q, dois=dois) + ep = config['query-server'].get('sparql_endpoint') + return render_template('work.html', q=q, dois=dois, sparql_endpoint=ep) @main.route('/work/') @@ -2682,7 +2744,8 @@ def show_works(qs): """ qs = Q_PATTERN.findall(qs) - return render_template('works.html', qs=qs) + ep = config['query-server'].get('sparql_endpoint') + return render_template('works.html', qs=qs, sparql_endpoint=ep) @main.route('/about') @@ -2726,7 +2789,8 @@ def show_wikiproject(q): Rendered HTML page for specific WikiProject. """ - return render_template('wikiproject.html', q=q) + ep = config['query-server'].get('sparql_endpoint') + return render_template('wikiproject.html', q=q, sparql_endpoint=ep) @main.route('/favicon.ico') @@ -2753,11 +2817,12 @@ def show_aspect_missing(aspect, q): Rendered HTML. """ + ep = config['query-server'].get('sparql_endpoint') try: return render_template('{aspect}-curation.html'.format(aspect=aspect), - q=q) + q=q, sparql_endpoint=ep) except TemplateNotFound: - return render_template('q_curation.html', q=q, aspect=aspect) + return render_template('q_curation.html', q=q, aspect=aspect, sparql_endpoint=ep) def page_not_found(e): From 4cd2aa21d0b3e471e727ab36b8151b86416c90c0 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 8 Jun 2024 13:46:20 +0200 Subject: [PATCH 4/9] Made the edit URL configurable too --- scholia/app/static/scholia.js | 18 ++- scholia/app/templates/base.html | 4 +- scholia/app/views.py | 191 +++++++++++++++++++++----------- scholia/config.py | 1 + 4 files changed, 143 insertions(+), 71 deletions(-) diff --git a/scholia/app/static/scholia.js b/scholia/app/static/scholia.js index 5c38912ca..00a56c7b7 100644 --- a/scholia/app/static/scholia.js +++ b/scholia/app/static/scholia.js @@ -243,14 +243,17 @@ function sparqlDataToSimpleData(response) { function sparqlToDataTablePost(sparql, element, filename, options = {}) { sparqlToDataTablePost( - "https://query.wikidata.org/sparql", sparql, element, filename, options + "https://query.wikidata.org/sparql", + "https://query.wikidata.org/", + sparql, element, filename, options ); } -function sparqlToDataTablePost(url, sparql, element, filename, options = {}) { +function sparqlToDataTablePost(url, editURL, sparql, element, filename, options = {}) { // Options: paging= if (!url) url = "https://query.wikidata.org/sparql"; + if (!editURL) editURL = "https://query.wikidata.org/"; var paging = (typeof options.paging === 'undefined') ? true : options.paging; var sDom = (typeof options.sDom === 'undefined') ? 'lfrtip' : options.sDom; @@ -288,7 +291,7 @@ function sparqlToDataTablePost(url, sparql, element, filename, options = {}) { }); $(element).append( - 'Wikidata Query Service' + 'Wikidata Query Service' + '') @@ -641,7 +648,8 @@ def show_catalogue(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('catalogue.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('catalogue.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/catalogue/') @@ -673,7 +681,8 @@ def show_dataset(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('dataset.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('dataset.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/dataset/') @@ -705,7 +714,8 @@ def show_dataset_export(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('dataset-export.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('dataset-export.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/clinical-trial/') @@ -737,7 +747,8 @@ def show_clinical_trial(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('clinical-trial.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('clinical-trial.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/countries/' + qs_pattern) @@ -757,7 +768,8 @@ def show_countries(qs): """ qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') - return render_template('countries.html', qs=qs, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('countries.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/country/') @@ -789,7 +801,8 @@ def show_country(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('country.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('country.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/country/' + q1_pattern + '/topic/' + q2_pattern) @@ -810,7 +823,8 @@ def show_country_topic(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('country-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('country-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/disease/' + q_pattern) @@ -829,7 +843,8 @@ def show_disease(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('disease.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('disease.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/disease/') @@ -861,7 +876,8 @@ def redirect_doi(doi): q = qs[0] return redirect(url_for('app.show_work', q=q), code=302) ep = config['query-server'].get('sparql_endpoint') - return render_template('404-doi.html', doi=doi, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('404-doi.html', doi=doi, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/doi-prefix/') @@ -880,7 +896,8 @@ def redirect_doi_prefix(doi): q = qs[0] return redirect(url_for('app.show_publisher', q=q), code=302) ep = config['query-server'].get('sparql_endpoint') - return render_template('404.html', doi=doi, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('404.html', doi=doi, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/event/' + q_pattern) @@ -899,7 +916,8 @@ def show_event(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('event.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('event.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/event/') @@ -931,7 +949,8 @@ def show_event_series(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('event-series.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('event-series.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/event-series/') @@ -1026,7 +1045,8 @@ def redirect_inchikey(inchikey): q = qs[0] return redirect(url_for('app.show_chemical', q=q), code=302) ep = config['query-server'].get('sparql_endpoint') - return render_template('404-chemical.html', inchikey=inchikey, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('404-chemical.html', inchikey=inchikey, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/issn/') @@ -1062,7 +1082,8 @@ def show_language(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('language.html', q=q, datetime=datetime, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('language.html', q=q, datetime=datetime, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/language') @@ -1107,7 +1128,8 @@ def show_lexeme(lexeme): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('lexeme.html', lexeme=lexeme, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('lexeme.html', lexeme=lexeme, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/license/' + q_pattern) @@ -1126,7 +1148,8 @@ def show_license(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('license.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('license.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/license/') @@ -1171,7 +1194,8 @@ def show_location(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('location.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('location.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/location/' + q1_pattern + '/topic/' + q2_pattern) @@ -1192,7 +1216,8 @@ def show_location_topic(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('location-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('location-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/mesh/') @@ -1418,7 +1443,8 @@ def show_ontology(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('ontology.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('ontology.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/organization/' + q_pattern) @@ -1437,7 +1463,8 @@ def show_organization(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('organization.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('organization.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/organization/') @@ -1493,7 +1520,8 @@ def show_organization_topic(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('organization-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('organization-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/organization/' + q1_pattern + '/use/' + q2_pattern) @@ -1514,7 +1542,8 @@ def show_organization_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('organization-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('organization-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/organizations/' + qs_pattern) @@ -1534,7 +1563,8 @@ def show_organizations(qs): """ qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') - return render_template('organizations.html', qs=qs, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('organizations.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/printer/' + q_pattern) @@ -1553,7 +1583,8 @@ def show_printer(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('printer.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('printer.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/printer/') @@ -1585,7 +1616,8 @@ def show_protein(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('protein.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('protein.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/protein/') @@ -1617,7 +1649,8 @@ def show_project(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('project.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('project.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/project/') @@ -1693,7 +1726,8 @@ def show_gene(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('gene.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('gene.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/gene/') @@ -1725,6 +1759,7 @@ def show_taxon(q): """ ep = config['query-server'].get('sparql_endpoint') + editurl = config['query-server'].get('sparql_editurl') return render_template('taxon.html', q=q) @@ -1764,9 +1799,10 @@ def show_q_to_bibliography_templates(): wikitext = q_to_bibliography_templates(q) ep = config['query-server'].get('sparql_endpoint') + editurl = config['query-server'].get('sparql_editurl') return render_template('q-to-bibliography-templates.html', q=q, - wikitext=wikitext, sparql_endpoint=ep) + wikitext=wikitext, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/software/' + q_pattern) @@ -1785,7 +1821,8 @@ def show_software(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('software.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('software.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/software/') @@ -1817,7 +1854,8 @@ def show_software_export(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('software-export.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('software-export.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/text-to-topics', methods=['POST', 'GET']) @@ -1869,7 +1907,8 @@ def show_topic(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('topic.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('topic.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/topic/' + q_pattern + '/latest-works/rss') @@ -1925,7 +1964,8 @@ def show_topic_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('topic-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('topic-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/topics/' + qs_pattern) @@ -1953,7 +1993,8 @@ def show_topics(qs): return redirect(url_for('app.show_topic', q=qs[0]), code=301) else: ep = config['query-server'].get('sparql_endpoint') - return render_template('topics.html', qs=qs, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('topics.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/podcast/' + q_pattern) @@ -1972,8 +2013,9 @@ def show_podcast(q): """ ep = config['query-server'].get('sparql_endpoint') + editurl = config['query-server'].get('sparql_editurl') return render_template( - 'podcast.html', q=q, sparql_endpoint=ep) + 'podcast.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/podcast-season/' + q_pattern) @@ -1992,8 +2034,9 @@ def show_podcast_season(q): """ ep = config['query-server'].get('sparql_endpoint') + editurl = config['query-server'].get('sparql_editurl') return render_template( - 'podcast-season.html', q=q, sparql_endpoint=ep) + 'podcast-season.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/podcast-episode/' + q_pattern) @@ -2012,8 +2055,9 @@ def show_podcast_episode(q): """ ep = config['query-server'].get('sparql_endpoint') + editurl = config['query-server'].get('sparql_editurl') return render_template( - 'podcast-episode.html', q=q, sparql_endpoint=ep) + 'podcast-episode.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/podcast/random') @@ -2041,7 +2085,8 @@ def show_podcast_in_language(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('podcast-language.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('podcast-language.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/podcast/') @@ -2075,6 +2120,7 @@ def show_chemical(q): entities = wb_get_entities([q]) smiles = entity_to_smiles(entities[q]) ep = config['query-server'].get('sparql_endpoint') + editurl = config['query-server'].get('sparql_editurl') return render_template( 'chemical.html', q=q, sparql_endpoint=ep, @@ -2125,7 +2171,8 @@ def show_chemical_element(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('chemical-element.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('chemical-element.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/chemical-element/') @@ -2159,6 +2206,7 @@ def show_chemical_class(q): entities = wb_get_entities([q]) smiles = entity_to_smiles(entities[q]) ep = config['query-server'].get('sparql_endpoint') + editurl = config['query-server'].get('sparql_editurl') return render_template( 'chemical-class.html', q=q, sparql_endpoint=ep, @@ -2215,7 +2263,8 @@ def show_venue(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('venue.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('venue.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/venue/' + q_pattern + '/cito') @@ -2254,7 +2303,8 @@ def show_venue_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('venue-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('venue-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/work/' + q_pattern + '/cito') @@ -2293,7 +2343,8 @@ def show_work_cito_intention(q, q2): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('work-cito-intention.html', q=q, q2=q2, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('work-cito-intention.html', q=q, q2=q2, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/work/' + q_pattern + '/export') @@ -2312,7 +2363,8 @@ def show_work_export(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('work-export.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('work-export.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/work/random') @@ -2345,7 +2397,8 @@ def show_cito(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('cito.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('cito.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/cito/') @@ -2417,7 +2470,8 @@ def show_venues(qs): """ qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') - return render_template('venues.html', qs=qs, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('venues.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/series/' + q_pattern) @@ -2436,7 +2490,8 @@ def show_series(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('series.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('series.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/series/') @@ -2468,7 +2523,8 @@ def show_complex(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('complex.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('complex.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/complex/') @@ -2500,7 +2556,8 @@ def show_pathway(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('pathway.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('pathway.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/pathway/') @@ -2527,7 +2584,8 @@ def show_publisher(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('publisher.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('publisher.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/publisher/') @@ -2594,7 +2652,8 @@ def show_sponsor(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('sponsor.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('sponsor.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/sponsor/') @@ -2648,7 +2707,8 @@ def show_use(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('use.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('use.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/use/') @@ -2689,7 +2749,8 @@ def show_uses(qs): return redirect(url_for('app.show_use', q=qs[0]), code=301) else: ep = config['query-server'].get('sparql_endpoint') - return render_template('uses.html', qs=qs, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('uses.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/work/' + q_pattern) @@ -2712,7 +2773,8 @@ def show_work(q): except Exception: dois = [] ep = config['query-server'].get('sparql_endpoint') - return render_template('work.html', q=q, dois=dois, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('work.html', q=q, dois=dois, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/work/') @@ -2745,7 +2807,8 @@ def show_works(qs): """ qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') - return render_template('works.html', qs=qs, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('works.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/about') @@ -2790,7 +2853,8 @@ def show_wikiproject(q): """ ep = config['query-server'].get('sparql_endpoint') - return render_template('wikiproject.html', q=q, sparql_endpoint=ep) + editurl = config['query-server'].get('sparql_editurl') + return render_template('wikiproject.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/favicon.ico') @@ -2818,11 +2882,12 @@ def show_aspect_missing(aspect, q): """ ep = config['query-server'].get('sparql_endpoint') + editurl = config['query-server'].get('sparql_editurl') try: return render_template('{aspect}-curation.html'.format(aspect=aspect), - q=q, sparql_endpoint=ep) + q=q, sparql_endpoint=ep, sparql_editURL=editurl) except TemplateNotFound: - return render_template('q_curation.html', q=q, aspect=aspect, sparql_endpoint=ep) + return render_template('q_curation.html', q=q, aspect=aspect, sparql_endpoint=ep, sparql_editURL=editurl) def page_not_found(e): diff --git a/scholia/config.py b/scholia/config.py index d3c00e2c3..9ac84175e 100644 --- a/scholia/config.py +++ b/scholia/config.py @@ -20,6 +20,7 @@ DEFAULTS = """ [query-server] sparql_endpoint = https://query.wikidata.org/sparql +sparql_editurl = https://query.wikidata.org/# [requests] user_agent = Scholia From b74885a846b5516d9fad360fb86d373c0abc98fe Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 8 Jun 2024 14:00:28 +0200 Subject: [PATCH 5/9] Fixed 'tox' warning, including a few missing parameter assignments --- scholia/app/views.py | 187 ++++++++++++++++++++++++++++--------------- 1 file changed, 124 insertions(+), 63 deletions(-) diff --git a/scholia/app/views.py b/scholia/app/views.py index b5c0db2a5..89a2a005f 100644 --- a/scholia/app/views.py +++ b/scholia/app/views.py @@ -112,7 +112,8 @@ def index_statistics(): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('index-statistics.html', sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('index-statistics.html', sparql_endpoint=ep, + sparql_editURL=editurl) @main.route("/" + l_pattern) @@ -398,7 +399,8 @@ def show_author(q): else: first_initial, last_name = '', '' return render_template('author.html', q=q, first_initial=first_initial, - last_name=last_name, sparql_endpoint=ep, sparql_editURL=editurl) + last_name=last_name, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/author/' + q_pattern + '/latest-works/rss') @@ -435,7 +437,8 @@ def show_author_index(): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('author-index.html', sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('author-index.html', sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/author/random') @@ -471,7 +474,8 @@ def show_author_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('author-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('author-use.html', q1=q1, q2=q2, q=q1, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/authors/' + qs_pattern) @@ -500,7 +504,8 @@ def show_authors(qs): else: ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('authors.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('authors.html', qs=qs, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/award/' + q_pattern) @@ -520,7 +525,8 @@ def show_award(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('award.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('award.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/award/') @@ -535,7 +541,8 @@ def show_award_index(): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('award-index.html', sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('award-index.html', sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/cas/') @@ -649,7 +656,8 @@ def show_catalogue(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('catalogue.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('catalogue.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/catalogue/') @@ -682,7 +690,8 @@ def show_dataset(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('dataset.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('dataset.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/dataset/') @@ -715,7 +724,8 @@ def show_dataset_export(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('dataset-export.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('dataset-export.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/clinical-trial/') @@ -748,7 +758,8 @@ def show_clinical_trial(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('clinical-trial.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('clinical-trial.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/countries/' + qs_pattern) @@ -769,7 +780,8 @@ def show_countries(qs): qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('countries.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('countries.html', qs=qs, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/country/') @@ -802,7 +814,8 @@ def show_country(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('country.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('country.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/country/' + q1_pattern + '/topic/' + q2_pattern) @@ -824,7 +837,8 @@ def show_country_topic(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('country-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('country-topic.html', q1=q1, q2=q2, q=q1, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/disease/' + q_pattern) @@ -844,7 +858,8 @@ def show_disease(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('disease.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('disease.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/disease/') @@ -877,7 +892,8 @@ def redirect_doi(doi): return redirect(url_for('app.show_work', q=q), code=302) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('404-doi.html', doi=doi, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('404-doi.html', doi=doi, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/doi-prefix/') @@ -897,7 +913,8 @@ def redirect_doi_prefix(doi): return redirect(url_for('app.show_publisher', q=q), code=302) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('404.html', doi=doi, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('404.html', doi=doi, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/event/' + q_pattern) @@ -917,7 +934,8 @@ def show_event(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('event.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('event.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/event/') @@ -950,7 +968,8 @@ def show_event_series(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('event-series.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('event-series.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/event-series/') @@ -1046,7 +1065,8 @@ def redirect_inchikey(inchikey): return redirect(url_for('app.show_chemical', q=q), code=302) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('404-chemical.html', inchikey=inchikey, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('404-chemical.html', inchikey=inchikey, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/issn/') @@ -1083,7 +1103,8 @@ def show_language(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('language.html', q=q, datetime=datetime, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('language.html', q=q, datetime=datetime, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/language') @@ -1129,7 +1150,8 @@ def show_lexeme(lexeme): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('lexeme.html', lexeme=lexeme, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('lexeme.html', lexeme=lexeme, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/license/' + q_pattern) @@ -1149,7 +1171,8 @@ def show_license(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('license.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('license.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/license/') @@ -1195,7 +1218,8 @@ def show_location(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('location.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('location.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/location/' + q1_pattern + '/topic/' + q2_pattern) @@ -1217,7 +1241,8 @@ def show_location_topic(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('location-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('location-topic.html', q1=q1, q2=q2, q=q1, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/mesh/') @@ -1444,7 +1469,8 @@ def show_ontology(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('ontology.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('ontology.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/organization/' + q_pattern) @@ -1464,7 +1490,8 @@ def show_organization(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('organization.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('organization.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/organization/') @@ -1521,7 +1548,8 @@ def show_organization_topic(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('organization-topic.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('organization-topic.html', q1=q1, q2=q2, q=q1, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/organization/' + q1_pattern + '/use/' + q2_pattern) @@ -1543,7 +1571,8 @@ def show_organization_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('organization-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('organization-use.html', q1=q1, q2=q2, q=q1, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/organizations/' + qs_pattern) @@ -1564,7 +1593,8 @@ def show_organizations(qs): qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('organizations.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('organizations.html', qs=qs, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/printer/' + q_pattern) @@ -1584,7 +1614,8 @@ def show_printer(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('printer.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('printer.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/printer/') @@ -1617,7 +1648,8 @@ def show_protein(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('protein.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('protein.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/protein/') @@ -1650,7 +1682,8 @@ def show_project(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('project.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('project.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/project/') @@ -1727,7 +1760,8 @@ def show_gene(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('gene.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('gene.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/gene/') @@ -1760,7 +1794,8 @@ def show_taxon(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('taxon.html', q=q) + return render_template('taxon.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/taxon/') @@ -1802,7 +1837,8 @@ def show_q_to_bibliography_templates(): editurl = config['query-server'].get('sparql_editurl') return render_template('q-to-bibliography-templates.html', q=q, - wikitext=wikitext, sparql_endpoint=ep, sparql_editURL=editurl) + wikitext=wikitext, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/software/' + q_pattern) @@ -1822,7 +1858,8 @@ def show_software(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('software.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('software.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/software/') @@ -1855,7 +1892,8 @@ def show_software_export(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('software-export.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('software-export.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/text-to-topics', methods=['POST', 'GET']) @@ -1908,7 +1946,8 @@ def show_topic(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('topic.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('topic.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/topic/' + q_pattern + '/latest-works/rss') @@ -1965,7 +2004,8 @@ def show_topic_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('topic-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('topic-use.html', q1=q1, q2=q2, q=q1, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/topics/' + qs_pattern) @@ -1994,7 +2034,8 @@ def show_topics(qs): else: ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('topics.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('topics.html', qs=qs, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/podcast/' + q_pattern) @@ -2057,7 +2098,8 @@ def show_podcast_episode(q): ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') return render_template( - 'podcast-episode.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + 'podcast-episode.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/podcast/random') @@ -2086,7 +2128,8 @@ def show_podcast_in_language(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('podcast-language.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('podcast-language.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/podcast/') @@ -2123,7 +2166,7 @@ def show_chemical(q): editurl = config['query-server'].get('sparql_editurl') return render_template( 'chemical.html', - q=q, sparql_endpoint=ep, + q=q, sparql_endpoint=ep, sparql_editURL=editurl, smiles=smiles, third_parties_enabled=current_app.third_parties_enabled) @@ -2172,7 +2215,8 @@ def show_chemical_element(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('chemical-element.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('chemical-element.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/chemical-element/') @@ -2209,7 +2253,7 @@ def show_chemical_class(q): editurl = config['query-server'].get('sparql_editurl') return render_template( 'chemical-class.html', - q=q, sparql_endpoint=ep, + q=q, sparql_endpoint=ep, sparql_editURL=editurl, smiles=smiles, third_parties_enabled=current_app.third_parties_enabled) @@ -2264,7 +2308,8 @@ def show_venue(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('venue.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('venue.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/venue/' + q_pattern + '/cito') @@ -2304,7 +2349,8 @@ def show_venue_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('venue-use.html', q1=q1, q2=q2, q=q1, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('venue-use.html', q1=q1, q2=q2, q=q1, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/work/' + q_pattern + '/cito') @@ -2344,7 +2390,8 @@ def show_work_cito_intention(q, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('work-cito-intention.html', q=q, q2=q2, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('work-cito-intention.html', q=q, q2=q2, + sparql_endpoint=ep, sparql_editURL=editurl) @main.route('/work/' + q_pattern + '/export') @@ -2364,7 +2411,8 @@ def show_work_export(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('work-export.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('work-export.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/work/random') @@ -2398,7 +2446,8 @@ def show_cito(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('cito.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('cito.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/cito/') @@ -2471,7 +2520,8 @@ def show_venues(qs): qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('venues.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('venues.html', qs=qs, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/series/' + q_pattern) @@ -2491,7 +2541,8 @@ def show_series(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('series.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('series.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/series/') @@ -2524,7 +2575,8 @@ def show_complex(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('complex.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('complex.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/complex/') @@ -2557,7 +2609,8 @@ def show_pathway(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('pathway.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('pathway.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/pathway/') @@ -2585,7 +2638,8 @@ def show_publisher(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('publisher.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('publisher.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/publisher/') @@ -2653,7 +2707,8 @@ def show_sponsor(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('sponsor.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('sponsor.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/sponsor/') @@ -2708,7 +2763,8 @@ def show_use(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('use.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('use.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/use/') @@ -2750,7 +2806,8 @@ def show_uses(qs): else: ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('uses.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('uses.html', qs=qs, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/work/' + q_pattern) @@ -2774,7 +2831,8 @@ def show_work(q): dois = [] ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('work.html', q=q, dois=dois, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('work.html', q=q, dois=dois, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/work/') @@ -2808,7 +2866,8 @@ def show_works(qs): qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('works.html', qs=qs, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('works.html', qs=qs, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/about') @@ -2854,7 +2913,8 @@ def show_wikiproject(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('wikiproject.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('wikiproject.html', q=q, sparql_endpoint=ep, + sparql_editURL=editurl) @main.route('/favicon.ico') @@ -2887,7 +2947,8 @@ def show_aspect_missing(aspect, q): return render_template('{aspect}-curation.html'.format(aspect=aspect), q=q, sparql_endpoint=ep, sparql_editURL=editurl) except TemplateNotFound: - return render_template('q_curation.html', q=q, aspect=aspect, sparql_endpoint=ep, sparql_editURL=editurl) + return render_template('q_curation.html', q=q, aspect=aspect, + sparql_endpoint=ep, sparql_editURL=editurl) def page_not_found(e): From 4749ec52573d9217656ac0e6c30d72a1f4e7a4e5 Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 8 Jun 2024 15:30:51 +0200 Subject: [PATCH 6/9] Also pass around the embed URL --- scholia/app/static/scholia.js | 21 ++- scholia/app/templates/base.html | 3 +- scholia/app/views.py | 224 ++++++++++++++++++++++---------- scholia/config.py | 1 + 4 files changed, 176 insertions(+), 73 deletions(-) diff --git a/scholia/app/static/scholia.js b/scholia/app/static/scholia.js index 00a56c7b7..a4fce7b24 100644 --- a/scholia/app/static/scholia.js +++ b/scholia/app/static/scholia.js @@ -443,14 +443,27 @@ function sparqlToDataTable(url, editURL, sparql, element, filename, options = {} function sparqlToIframe(sparql, element, filename) { + sparqlToIframe( + "https://query.wikidata.org/sparql", + "https://query.wikidata.org/", + "https://query.wikidata.org/embed.html#", + sparql, element, filename, options + ); +} + + +function sparqlToIframe(url, editURL, embedURL, sparql, element, filename) { let $iframe = $(element); - var url = "https://query.wikidata.org/embed.html#" + encodeURIComponent(sparql); + if (!url) url = "https://query.wikidata.org/sparql"; + if (!editURL) editURL = "https://query.wikidata.org/"; + if (!embedURL) embedURL = "https://query.wikidata.org/embed.html#"; + + const wikidata_sparql = url + "?query=" + encodeURIComponent(sparql); + const wikidata_query = editURL + encodeURIComponent(sparql); + var url = embedURL + encodeURIComponent(sparql); $iframe.attr('data-src', url); $iframe.attr('loading', 'lazy'); - const wikidata_sparql = "https://query.wikidata.org/sparql?query=" + encodeURIComponent(sparql); - const wikidata_query = "https://query.wikidata.org/#" + encodeURIComponent(sparql); - // Define the options for the Intersection Observer const options = { root: null, diff --git a/scholia/app/templates/base.html b/scholia/app/templates/base.html index c1ac8fd3a..3e5faa3ac 100644 --- a/scholia/app/templates/base.html +++ b/scholia/app/templates/base.html @@ -22,7 +22,8 @@ {% macro sparql_to_iframe(panel) -%} // {{ panel }} iframe -sparqlToIframe(`# tool: scholia +sparqlToIframe("{{ sparql_endpoint }}", "{{ sparql_editURL }}", +"{{ sparql_embedURL }}", `# tool: scholia {% include aspect + '_' + panel + '.sparql' %}`, "#{{ panel }}-iframe", "{{ aspect }}_{{ panel }}.sparql"); {%- endmacro %} diff --git a/scholia/app/views.py b/scholia/app/views.py index 89a2a005f..6186bb79f 100644 --- a/scholia/app/views.py +++ b/scholia/app/views.py @@ -112,8 +112,9 @@ def index_statistics(): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('index-statistics.html', sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route("/" + l_pattern) @@ -392,6 +393,7 @@ def show_author(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') entities = wb_get_entities([q]) name = entity_to_name(entities[q]) if name: @@ -400,7 +402,7 @@ def show_author(q): first_initial, last_name = '', '' return render_template('author.html', q=q, first_initial=first_initial, last_name=last_name, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/author/' + q_pattern + '/latest-works/rss') @@ -437,8 +439,9 @@ def show_author_index(): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('author-index.html', sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/author/random') @@ -474,8 +477,10 @@ def show_author_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('author-use.html', q1=q1, q2=q2, q=q1, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/authors/' + qs_pattern) @@ -504,8 +509,10 @@ def show_authors(qs): else: ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('authors.html', qs=qs, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/award/' + q_pattern) @@ -525,8 +532,9 @@ def show_award(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('award.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/award/') @@ -541,8 +549,9 @@ def show_award_index(): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('award-index.html', sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/cas/') @@ -656,8 +665,9 @@ def show_catalogue(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('catalogue.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/catalogue/') @@ -690,8 +700,9 @@ def show_dataset(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('dataset.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/dataset/') @@ -724,8 +735,9 @@ def show_dataset_export(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('dataset-export.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/clinical-trial/') @@ -758,8 +770,9 @@ def show_clinical_trial(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('clinical-trial.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/countries/' + qs_pattern) @@ -780,8 +793,9 @@ def show_countries(qs): qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('countries.html', qs=qs, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/country/') @@ -814,8 +828,9 @@ def show_country(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('country.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/country/' + q1_pattern + '/topic/' + q2_pattern) @@ -837,8 +852,10 @@ def show_country_topic(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('country-topic.html', q1=q1, q2=q2, q=q1, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/disease/' + q_pattern) @@ -858,8 +875,9 @@ def show_disease(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('disease.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/disease/') @@ -892,8 +910,9 @@ def redirect_doi(doi): return redirect(url_for('app.show_work', q=q), code=302) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('404-doi.html', doi=doi, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/doi-prefix/') @@ -913,8 +932,9 @@ def redirect_doi_prefix(doi): return redirect(url_for('app.show_publisher', q=q), code=302) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('404.html', doi=doi, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/event/' + q_pattern) @@ -934,8 +954,9 @@ def show_event(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('event.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/event/') @@ -968,8 +989,9 @@ def show_event_series(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('event-series.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/event-series/') @@ -1065,8 +1087,10 @@ def redirect_inchikey(inchikey): return redirect(url_for('app.show_chemical', q=q), code=302) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('404-chemical.html', inchikey=inchikey, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/issn/') @@ -1103,8 +1127,10 @@ def show_language(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('language.html', q=q, datetime=datetime, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/language') @@ -1150,8 +1176,9 @@ def show_lexeme(lexeme): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('lexeme.html', lexeme=lexeme, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/license/' + q_pattern) @@ -1171,8 +1198,9 @@ def show_license(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('license.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/license/') @@ -1218,8 +1246,9 @@ def show_location(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('location.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/location/' + q1_pattern + '/topic/' + q2_pattern) @@ -1241,8 +1270,10 @@ def show_location_topic(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('location-topic.html', q1=q1, q2=q2, q=q1, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/mesh/') @@ -1469,8 +1500,9 @@ def show_ontology(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('ontology.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/organization/' + q_pattern) @@ -1490,8 +1522,9 @@ def show_organization(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('organization.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/organization/') @@ -1548,8 +1581,10 @@ def show_organization_topic(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('organization-topic.html', q1=q1, q2=q2, q=q1, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/organization/' + q1_pattern + '/use/' + q2_pattern) @@ -1571,8 +1606,10 @@ def show_organization_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('organization-use.html', q1=q1, q2=q2, q=q1, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/organizations/' + qs_pattern) @@ -1593,8 +1630,10 @@ def show_organizations(qs): qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('organizations.html', qs=qs, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/printer/' + q_pattern) @@ -1614,8 +1653,9 @@ def show_printer(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('printer.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/printer/') @@ -1648,8 +1688,9 @@ def show_protein(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('protein.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/protein/') @@ -1682,8 +1723,9 @@ def show_project(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('project.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/project/') @@ -1760,8 +1802,9 @@ def show_gene(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('gene.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/gene/') @@ -1794,8 +1837,9 @@ def show_taxon(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('taxon.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/taxon/') @@ -1835,10 +1879,11 @@ def show_q_to_bibliography_templates(): ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('q-to-bibliography-templates.html', q=q, wikitext=wikitext, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/software/' + q_pattern) @@ -1858,8 +1903,9 @@ def show_software(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('software.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/software/') @@ -1892,8 +1938,9 @@ def show_software_export(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('software-export.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/text-to-topics', methods=['POST', 'GET']) @@ -1946,8 +1993,10 @@ def show_topic(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('topic.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/topic/' + q_pattern + '/latest-works/rss') @@ -2004,8 +2053,10 @@ def show_topic_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('topic-use.html', q1=q1, q2=q2, q=q1, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/topics/' + qs_pattern) @@ -2034,8 +2085,10 @@ def show_topics(qs): else: ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') - return render_template('topics.html', qs=qs, sparql_endpoint=ep, - sparql_editURL=editurl) + embedurl = config['query-server'].get('sparql_embedurl') + return render_template('topics.html', qs=qs, sparql_endpoint=ep, + sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/podcast/' + q_pattern) @@ -2055,8 +2108,10 @@ def show_podcast(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template( - 'podcast.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + 'podcast.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/podcast-season/' + q_pattern) @@ -2076,8 +2131,10 @@ def show_podcast_season(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template( - 'podcast-season.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl) + 'podcast-season.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/podcast-episode/' + q_pattern) @@ -2097,9 +2154,10 @@ def show_podcast_episode(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template( 'podcast-episode.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/podcast/random') @@ -2128,8 +2186,9 @@ def show_podcast_in_language(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('podcast-language.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/podcast/') @@ -2164,10 +2223,11 @@ def show_chemical(q): smiles = entity_to_smiles(entities[q]) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template( 'chemical.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl, - smiles=smiles, + sparql_embedURL=embedurl, smiles=smiles, third_parties_enabled=current_app.third_parties_enabled) @@ -2215,8 +2275,9 @@ def show_chemical_element(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('chemical-element.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/chemical-element/') @@ -2251,10 +2312,11 @@ def show_chemical_class(q): smiles = entity_to_smiles(entities[q]) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template( 'chemical-class.html', q=q, sparql_endpoint=ep, sparql_editURL=editurl, - smiles=smiles, + sparql_embedURL=embedurl, smiles=smiles, third_parties_enabled=current_app.third_parties_enabled) @@ -2308,8 +2370,9 @@ def show_venue(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('venue.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/venue/' + q_pattern + '/cito') @@ -2349,8 +2412,10 @@ def show_venue_use(q1, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('venue-use.html', q1=q1, q2=q2, q=q1, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/work/' + q_pattern + '/cito') @@ -2390,8 +2455,10 @@ def show_work_cito_intention(q, q2): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('work-cito-intention.html', q=q, q2=q2, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/work/' + q_pattern + '/export') @@ -2411,8 +2478,9 @@ def show_work_export(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('work-export.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/work/random') @@ -2446,8 +2514,9 @@ def show_cito(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('cito.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/cito/') @@ -2464,7 +2533,11 @@ def show_cito_index(): in Wikidata. """ - return render_template('cito-index.html') + ep = config['query-server'].get('sparql_endpoint') + editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') + return render_template('cito-index.html', sparql_endpoint=ep, + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/venue/' + q_pattern + '/latest-works/rss') @@ -2520,8 +2593,9 @@ def show_venues(qs): qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('venues.html', qs=qs, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/series/' + q_pattern) @@ -2541,8 +2615,9 @@ def show_series(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('series.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/series/') @@ -2575,8 +2650,9 @@ def show_complex(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('complex.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/complex/') @@ -2609,8 +2685,9 @@ def show_pathway(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('pathway.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/pathway/') @@ -2638,8 +2715,9 @@ def show_publisher(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('publisher.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/publisher/') @@ -2707,8 +2785,9 @@ def show_sponsor(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('sponsor.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/sponsor/') @@ -2763,8 +2842,9 @@ def show_use(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('use.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/use/') @@ -2806,8 +2886,10 @@ def show_uses(qs): else: ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('uses.html', qs=qs, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, + sparql_embedURL=embedurl) @main.route('/work/' + q_pattern) @@ -2831,8 +2913,9 @@ def show_work(q): dois = [] ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('work.html', q=q, dois=dois, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/work/') @@ -2866,8 +2949,9 @@ def show_works(qs): qs = Q_PATTERN.findall(qs) ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('works.html', qs=qs, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/about') @@ -2913,8 +2997,9 @@ def show_wikiproject(q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') return render_template('wikiproject.html', q=q, sparql_endpoint=ep, - sparql_editURL=editurl) + sparql_editURL=editurl, sparql_embedURL=embedurl) @main.route('/favicon.ico') @@ -2943,12 +3028,15 @@ def show_aspect_missing(aspect, q): """ ep = config['query-server'].get('sparql_endpoint') editurl = config['query-server'].get('sparql_editurl') + embedurl = config['query-server'].get('sparql_embedurl') try: return render_template('{aspect}-curation.html'.format(aspect=aspect), - q=q, sparql_endpoint=ep, sparql_editURL=editurl) + q=q, sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) except TemplateNotFound: return render_template('q_curation.html', q=q, aspect=aspect, - sparql_endpoint=ep, sparql_editURL=editurl) + sparql_endpoint=ep, sparql_editURL=editurl, + sparql_embedURL=embedurl) def page_not_found(e): diff --git a/scholia/config.py b/scholia/config.py index 9ac84175e..6cd8cd2e9 100644 --- a/scholia/config.py +++ b/scholia/config.py @@ -21,6 +21,7 @@ [query-server] sparql_endpoint = https://query.wikidata.org/sparql sparql_editurl = https://query.wikidata.org/# +sparql_embedurl = https://query.wikidata.org/embed.html# [requests] user_agent = Scholia From 64d15f4fc9ce22702916733a42b4d6341ca6552f Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 8 Jun 2024 15:43:42 +0200 Subject: [PATCH 7/9] Removed four more hardcoded URLs --- scholia/rss.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scholia/rss.py b/scholia/rss.py index 7705cc090..a605fa649 100644 --- a/scholia/rss.py +++ b/scholia/rss.py @@ -360,7 +360,7 @@ def wb_get_venue_latest_works(q): 'type="application/rss+xml" />\n' query = VENUE_SPARQL_QUERY.format(q=q) - url = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql' + url = SPARQL_ENDPOINT params = {'query': query, 'format': 'json'} response = requests.get(url, params=params) data = response.json() @@ -404,7 +404,7 @@ def wb_get_topic_latest_works(q): 'type="application/rss+xml" />\n' query = TOPIC_SPARQL_QUERY.format(q=q) - url = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql' + url = SPARQL_ENDPOINT params = {'query': query, 'format': 'json'} response = requests.get(url, params=params) data = response.json() @@ -450,7 +450,7 @@ def wb_get_organization_latest_works(q): 'type="application/rss+xml" />\n' query = ORGANIZATION_SPARQL_QUERY.format(q=q) - url = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql' + url = SPARQL_ENDPOINT params = {'query': query, 'format': 'json'} response = requests.get(url, params=params) data = response.json() @@ -496,7 +496,7 @@ def wb_get_sponsor_latest_works(q): 'type="application/rss+xml" />\n' query = SPONSOR_SPARQL_QUERY.format(q=q) - url = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql' + url = SPARQL_ENDPOINT params = {'query': query, 'format': 'json'} response = requests.get(url, params=params) data = response.json() From bef684db181366276461617ea9917e286d7fc18c Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 8 Jun 2024 15:48:40 +0200 Subject: [PATCH 8/9] A few more hardcoded URLs replaced --- scholia/app/templates/author-index.html | 4 ++-- scholia/app/templates/base.html | 4 ++-- scholia/query.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scholia/app/templates/author-index.html b/scholia/app/templates/author-index.html index 985122762..ee788fc17 100644 --- a/scholia/app/templates/author-index.html +++ b/scholia/app/templates/author-index.html @@ -151,7 +151,7 @@

Redirects

resolver: 'custom', events: { search: debounce((searchTerm, callback) => { - var url = "https://query.wikidata.org/sparql"; + var url = "{{ sparql_endpoint }}"; var settings = { data: { query: ` @@ -211,7 +211,7 @@

Redirects

multiple: true, ajax: { delay: 300, - url: "https://query.wikidata.org/sparql", + url: "{{ sparql_endpoint }}", data: function (params) { let search_author = params.term return { diff --git a/scholia/app/templates/base.html b/scholia/app/templates/base.html index 3e5faa3ac..fa2aa7214 100644 --- a/scholia/app/templates/base.html +++ b/scholia/app/templates/base.html @@ -478,7 +478,7 @@ curationElement.classList.remove("d-none"); // this query opens the Wikidata item as a different aspect - var endpointUrl = 'https://query.wikidata.org/sparql'; + var endpointUrl = '{{ sparql_endpoint }}'; if ("{{q2}}".length) { var query = ` SELECT DISTINCT ?aspect @@ -555,7 +555,7 @@ } }).then(function () { if ("{{q2}}".length) { - var endpointUrl = 'https://query.wikidata.org/sparql'; + var endpointUrl = '{{ sparql_endpoint }}'; var query = "SELECT DISTINCT ?aspect WHERE {" query += '{ [] wdt:P921 wd:{{ q }} . BIND("topic" AS ?aspect) } }'; diff --git a/scholia/query.py b/scholia/query.py index cfdecef18..8128cb8e6 100644 --- a/scholia/query.py +++ b/scholia/query.py @@ -803,7 +803,7 @@ def omim_to_qs(omimID): query = 'select ?disease where {{ ?disease wdt:P492 "{omimID}" }}'.format( omimID=escape_string(omimID)) - url = 'https://query.wikidata.org/sparql' + url = SPARQL_ENDPOINT params = {'query': query, 'format': 'json'} response = requests.get(url, params=params, headers=HEADERS) data = response.json() From 4f593ae28d48f969e78f5849c44edf13bbafda6c Mon Sep 17 00:00:00 2001 From: Egon Willighagen Date: Sat, 22 Jun 2024 21:08:01 +0200 Subject: [PATCH 9/9] Cannot overload, so second function name --- scholia/app/static/scholia.js | 16 ++++++++-------- scholia/app/templates/base.html | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/scholia/app/static/scholia.js b/scholia/app/static/scholia.js index a4fce7b24..f560e4311 100644 --- a/scholia/app/static/scholia.js +++ b/scholia/app/static/scholia.js @@ -208,7 +208,7 @@ function addReloadButton(element, callback) { } } -function sparqlToResponse(endpointUrl, sparql, doneCallback) { +function sparqlToResponse2(endpointUrl, sparql, doneCallback) { var settings = { headers: { Accept: "application/sparql-results+json" }, data: { query: sparql }, @@ -218,7 +218,7 @@ function sparqlToResponse(endpointUrl, sparql, doneCallback) { function sparqlToResponse(sparql, doneCallback) { - return sparqlToResponse( + return sparqlToResponse2( "https://query.wikidata.org/bigdata/namespace/wdq/sparql", sparql, doneCallback ); @@ -242,7 +242,7 @@ function sparqlDataToSimpleData(response) { function sparqlToDataTablePost(sparql, element, filename, options = {}) { - sparqlToDataTablePost( + sparqlToDataTablePost2( "https://query.wikidata.org/sparql", "https://query.wikidata.org/", sparql, element, filename, options @@ -250,7 +250,7 @@ function sparqlToDataTablePost(sparql, element, filename, options = {}) { } -function sparqlToDataTablePost(url, editURL, sparql, element, filename, options = {}) { +function sparqlToDataTablePost2(url, editURL, sparql, element, filename, options = {}) { // Options: paging= if (!url) url = "https://query.wikidata.org/sparql"; if (!editURL) editURL = "https://query.wikidata.org/"; @@ -304,7 +304,7 @@ function sparqlToDataTablePost(url, editURL, sparql, element, filename, options function sparqlToDataTable(sparql, element, filename, options = {}) { - sparqlToDataTablePost( + sparqlToDataTablePost2( "https://query.wikidata.org/sparql", "https://query.wikidata.org/", sparql, element, filename, options @@ -312,7 +312,7 @@ function sparqlToDataTable(sparql, element, filename, options = {}) { } -function sparqlToDataTable(url, editURL, sparql, element, filename, options = {}) { +function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {}) { // Options: paging=true if (!url) url = "https://query.wikidata.org/sparql"; if (!editURL) editURL = "https://query.wikidata.org/"; @@ -443,7 +443,7 @@ function sparqlToDataTable(url, editURL, sparql, element, filename, options = {} function sparqlToIframe(sparql, element, filename) { - sparqlToIframe( + sparqlToIframe2( "https://query.wikidata.org/sparql", "https://query.wikidata.org/", "https://query.wikidata.org/embed.html#", @@ -452,7 +452,7 @@ function sparqlToIframe(sparql, element, filename) { } -function sparqlToIframe(url, editURL, embedURL, sparql, element, filename) { +function sparqlToIframe2(url, editURL, embedURL, sparql, element, filename) { let $iframe = $(element); if (!url) url = "https://query.wikidata.org/sparql"; if (!editURL) editURL = "https://query.wikidata.org/"; diff --git a/scholia/app/templates/base.html b/scholia/app/templates/base.html index fa2aa7214..3007b14e7 100644 --- a/scholia/app/templates/base.html +++ b/scholia/app/templates/base.html @@ -2,7 +2,7 @@ {% macro sparql_to_table_post(panel, options={}) -%} // {{ panel }} table -sparqlToDataTablePost("{{ sparql_endpoint }}", "{{ sparql_editURL }}", +sparqlToDataTablePost2("{{ sparql_endpoint }}", "{{ sparql_editURL }}", `# tool: scholia {% include aspect + '_' + panel + '.sparql' %} `, @@ -12,7 +12,7 @@ {% macro sparql_to_table(panel, options={}) -%} // {{ panel }} table -sparqlToDataTable("{{ sparql_endpoint }}", "{{ sparql_editURL }}", +sparqlToDataTable2("{{ sparql_endpoint }}", "{{ sparql_editURL }}", `# tool: scholia {% include aspect + '_' + panel + '.sparql' %} `, @@ -22,7 +22,7 @@ {% macro sparql_to_iframe(panel) -%} // {{ panel }} iframe -sparqlToIframe("{{ sparql_endpoint }}", "{{ sparql_editURL }}", +sparqlToIframe2("{{ sparql_endpoint }}", "{{ sparql_editURL }}", "{{ sparql_embedURL }}", `# tool: scholia {% include aspect + '_' + panel + '.sparql' %}`, "#{{ panel }}-iframe", "{{ aspect }}_{{ panel }}.sparql");