diff options
Diffstat (limited to 'wqflask/utility')
-rw-r--r-- | wqflask/utility/authentication_tools.py | 13 | ||||
-rw-r--r-- | wqflask/utility/helper_functions.py | 27 |
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())] |