aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2022-11-14 17:29:32 +0300
committerBonfaceKilz2022-11-16 11:01:32 +0300
commitfaeafb441d2b6517e7036bbfcc03b2e6b93d8a0c (patch)
treefbb72fce38f852eb65f1cf203297bb2a65bc3e65
parentfe3414198289526d1ec9816cf56ba1b916cae8d6 (diff)
downloadgenenetwork2-faeafb441d2b6517e7036bbfcc03b2e6b93d8a0c.tar.gz
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.
-rw-r--r--wqflask/wqflask/database.py8
-rw-r--r--wqflask/wqflask/views.py6
2 files changed, 13 insertions, 1 deletions
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