aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility
diff options
context:
space:
mode:
authorMunyoki Kilyungi2022-09-02 17:28:26 +0300
committerBonfaceKilz2022-09-08 14:26:19 +0300
commit72336a5876ddffba15aede5e02546e7dbf7a19f5 (patch)
treeb2c675adab8ec76ca2c7b924820fa3b55450a48d /wqflask/utility
parentf81265ac735b837d8241d366832d4b98c2080909 (diff)
downloadgenenetwork2-72336a5876ddffba15aede5e02546e7dbf7a19f5.tar.gz
Replace g.db with database_connection() context manager
* wqflask/base/mrna_assay_tissue_data.py: Replace "flask.g" with database_connection. (MrnaAssayTissueData.__init__): Use database_connection. (MrnaAssayTissueData.get_symbol_values_pairs): Ditto. * wqflask/base/species.py: Replace "Flask.g" imports with "database_connection". (Chromosomes.chromosomes): Use database_connection. * wqflask/base/trait.py: Import database_connection. (retrieve_trait_info): Use database_connection. * wqflask/utility/authentication_tools.py: Replace "flask.g" with database_connection. (get_group_code): Use database_connection. * wqflask/utility/helper_functions.py: Replace "flask.g" with "database_connection". (get_species_groups): Use database_connection. * wqflask/wqflask/db_info.py: Replace "Flask" and "g" with "database_connection". (InfoPage.get_info): Use database_connection. * wqflask/wqflask/do_search.py (DoSearch.execute): Use database_connection(). * wqflask/wqflask/external_tools/send_to_geneweaver.py: Replace "Flask" and "g" import with database_connection. (test_chip): Use database_connection. * wqflask/wqflask/external_tools/send_to_webgestalt.py: Replace "Flask, g" imports with database_connection. (test_chip): Use database_connection. * wqflask/wqflask/gsearch.py: Replace "Flask" and "g" import with database_connection. (GSearch.__init__): Use database_connection. * wqflask/wqflask/interval_analyst/GeneUtil.py (loadGenes): Use database_connection(). * wqflask/wqflask/show_trait/SampleList.py: Replace "flask.g import" with database_connection. (SampleList.get_attributes): Use database_connection. (SampleList.get_extra_attribute_values): Ditto. * wqflask/wqflask/show_trait/show_trait.py: Replace "Flask" and "g" import with database_connection. (ShowTrait.__init__): Use database_connection. (ShowTrait.get_external_links): Ditto. (get_nearest_marker): Ditto.
Diffstat (limited to 'wqflask/utility')
-rw-r--r--wqflask/utility/authentication_tools.py13
-rw-r--r--wqflask/utility/helper_functions.py27
2 files changed, 22 insertions, 18 deletions
diff --git a/wqflask/utility/authentication_tools.py b/wqflask/utility/authentication_tools.py
index 96cc0b00..a8c03fe2 100644
--- a/wqflask/utility/authentication_tools.py
+++ b/wqflask/utility/authentication_tools.py
@@ -85,12 +85,13 @@ def add_new_resource(dataset, trait_id=None):
def get_group_code(dataset):
- results = g.db.execute(
- "SELECT InbredSetCode from InbredSet where Name='{}'".format(
- dataset.group.name)).fetchone()
- if results[0]:
- return results[0]
- else:
+ with database_connection() as conn, conn.cursor() as cursor:
+ cursor.execute(
+ "SELECT InbredSetCode FROM InbredSet WHERE Name=%s",
+ (dataset.group.name,)
+ )
+ if results := cursor.fetchone():
+ return results[0]
return ""
diff --git a/wqflask/utility/helper_functions.py b/wqflask/utility/helper_functions.py
index 4229a91f..0c0794dc 100644
--- a/wqflask/utility/helper_functions.py
+++ b/wqflask/utility/helper_functions.py
@@ -4,7 +4,7 @@ from base.species import TheSpecies
from utility import hmac
-from flask import g
+from wqflask.database import database_connection
def get_species_dataset_trait(self, start_vars):
@@ -50,16 +50,19 @@ def get_trait_db_obs(self, trait_db_list):
def get_species_groups():
"""Group each species into a group"""
_menu = {}
-
- for species, group_name in g.db.execute(
+ species, group_name = None, None
+ with database_connection() as conn, conn.cursor() as cursor:
+ cursor.execute(
"SELECT s.MenuName, i.InbredSetName FROM InbredSet i "
"INNER JOIN Species s ON s.SpeciesId = i.SpeciesId "
- "ORDER BY i.SpeciesId ASC, i.Name ASC").fetchall():
- if species in _menu:
- if _menu.get(species):
- _menu = _menu[species].append(group_name)
- else:
- _menu[species] = [group_name]
- return [{"species": key,
- "groups": value} for key, value in
- list(_menu.items())]
+ "ORDER BY i.SpeciesId ASC, i.Name ASC"
+ )
+ for species, group_name in cursor.fetchall():
+ if species in _menu:
+ if _menu.get(species):
+ _menu = _menu[species].append(group_name)
+ else:
+ _menu[species] = [group_name]
+ return [{"species": key,
+ "groups": value} for key, value in
+ list(_menu.items())]