From faeafb441d2b6517e7036bbfcc03b2e6b93d8a0c Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Mon, 14 Nov 2022 17:29:32 +0300 Subject: Pass a sparql connection object to get_dataset_metadata * wqflask/wqflask/database.py (database_connection): New function. * wqflask/wqflask/views.py: Import sparql_connection (show_trait_page): Pass sparql_connection object to get_dataset_metadata. --- wqflask/wqflask/database.py | 8 ++++++++ wqflask/wqflask/views.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py index 663e2ebf..d2929488 100644 --- a/wqflask/wqflask/database.py +++ b/wqflask/wqflask/database.py @@ -1,6 +1,7 @@ # Module to initialize sqlalchemy with flask import os import sys +from SPARQLWrapper import JSON, SPARQLWrapper from typing import Tuple, Protocol, Any, Iterator from urllib.parse import urlparse import importlib @@ -60,3 +61,10 @@ def database_connection() -> Iterator[Connection]: yield connection finally: connection.close() + + +def sparql_connection(): + """Create a sparql objection that is used to query RDF""" + return SPARQLWrapper( + get_setting("SPARQL_ENDPOINT") + ) diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 8a0bede3..1b34e2f8 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -90,6 +90,7 @@ from base.webqtlConfig import TMPDIR from base.webqtlConfig import GENERATED_IMAGE_DIR from wqflask.database import database_connection +from wqflask.database import sparql_connection import jobs.jobs as jobs @@ -491,7 +492,10 @@ def show_trait_page(): metadata = ( template_vars.dataset.accession_id .bind( - lambda idx: get_dataset_metadata(f"GN{idx}") + lambda idx: get_dataset_metadata( + sparql_connection(), + f"GN{idx}" + ) ) ).data -- cgit v1.2.3