aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-06-22 12:12:26 +0300
committerFrederick Muriuki Muriithi2023-06-22 12:12:26 +0300
commit7d669eed50a0e39eaa2b4a4769e5d9bbefdb997a (patch)
tree585943056bd7df17e312da3a13a2d87ac12d259c /wqflask/utility
parent490b0bf8cc5891a23c8850185d21987b5476ba4f (diff)
downloadgenenetwork2-7d669eed50a0e39eaa2b4a4769e5d9bbefdb997a.tar.gz
Fetch configs from app object not modulesdecouple_tools_and_wqflask_app
Diffstat (limited to 'wqflask/utility')
-rw-r--r--wqflask/utility/authentication_tools.py8
-rw-r--r--wqflask/utility/pillow_utils.py5
-rw-r--r--wqflask/utility/startup_config.py18
3 files changed, 14 insertions, 17 deletions
diff --git a/wqflask/utility/authentication_tools.py b/wqflask/utility/authentication_tools.py
index 7d80b3fb..c42f5414 100644
--- a/wqflask/utility/authentication_tools.py
+++ b/wqflask/utility/authentication_tools.py
@@ -1,7 +1,7 @@
import json
import requests
-from flask import g
+from flask import g, current_app as app
from wqflask.database import database_connection
from base import webqtlConfig
@@ -9,7 +9,7 @@ from utility.redis_tools import (get_redis_conn,
get_resource_info,
get_resource_id,
add_resource)
-from utility.tools import GN_PROXY_URL
+from utility.tools import get_setting
Redis = get_redis_conn()
@@ -37,7 +37,7 @@ def check_resource_availability(dataset, user_id, trait_id=None):
return webqtlConfig.SUPER_PRIVILEGES
response = None
- the_url = f"{GN_PROXY_URL}available?resource={resource_id}&user={user_id}"
+ the_url = f"{get_setting(app, 'GN_PROXY_URL')}available?resource={resource_id}&user={user_id}"
try:
response = json.loads(requests.get(the_url).content)
except:
@@ -93,7 +93,7 @@ def get_group_code(dataset):
def check_admin(resource_id=None):
- the_url = GN_PROXY_URL + "available?resource={}&user={}".format(
+ the_url = get_setting('GN_PROXY_URL') + "available?resource={}&user={}".format(
resource_id, g.user_session.user_id)
try:
response = json.loads(requests.get(the_url).content)['admin']
diff --git a/wqflask/utility/pillow_utils.py b/wqflask/utility/pillow_utils.py
index e302df18..524a2be1 100644
--- a/wqflask/utility/pillow_utils.py
+++ b/wqflask/utility/pillow_utils.py
@@ -1,6 +1,7 @@
+from flask import current_app as app
from PIL import Image, ImageColor, ImageDraw, ImageFont
-from utility.tools import TEMPDIR
+from utility.tools import get_setting
BLACK = ImageColor.getrgb("black")
WHITE = ImageColor.getrgb("white")
@@ -15,7 +16,7 @@ def draw_rotated_text(canvas, text, font, xy, fill=BLACK, angle=-90):
draw_text = ImageDraw.Draw(tmp_img)
draw_text.text(text=text, xy=(0, 0), font=font, fill=fill)
tmp_img2 = tmp_img.rotate(angle, expand=1)
- tmp_img2.save("/{0}/{1}.png".format(TEMPDIR, text), format="png")
+ tmp_img2.save("/{0}/{1}.png".format(get_setting(app, 'TEMPDIR'), text), format="png")
canvas.paste(im=tmp_img2, box=tuple([int(i) for i in xy]))
# def draw_open_polygon(canvas: Image, xy: tuple, fill: ImageColor=WHITE, outline: ImageColor=BLACK):
diff --git a/wqflask/utility/startup_config.py b/wqflask/utility/startup_config.py
index 69cac124..3ff72518 100644
--- a/wqflask/utility/startup_config.py
+++ b/wqflask/utility/startup_config.py
@@ -1,7 +1,3 @@
-
-from wqflask import app
-
-from utility.tools import WEBSERVER_MODE
from utility.tools import show_settings
from utility.tools import get_setting_int
from utility.tools import get_setting
@@ -14,28 +10,28 @@ BOLD = '\033[1m'
ENDC = '\033[0m'
-def app_config():
+def app_config(app):
app.config['SESSION_TYPE'] = app.config.get('SESSION_TYPE', 'filesystem')
if not app.config.get('SECRET_KEY'):
import os
app.config['SECRET_KEY'] = str(os.urandom(24))
- mode = WEBSERVER_MODE
+ mode = get_setting(app, "WEBSERVER_MODE")
if mode in ["DEV", "DEBUG"]:
app.config['TEMPLATES_AUTO_RELOAD'] = True
if mode == "DEBUG":
app.debug = True
print("==========================================")
- show_settings()
+ show_settings(app)
- port = get_setting_int("SERVER_PORT")
+ port = get_setting_int(app, "SERVER_PORT")
- if get_setting_bool("USE_GN_SERVER"):
+ if get_setting_bool(app, "USE_GN_SERVER"):
print(f"GN2 API server URL is [{BLUE}GN_SERVER_URL{ENDC}]")
import requests
- page = requests.get(get_setting("GN_SERVER_URL"))
+ page = requests.get(get_setting(app, "GN_SERVER_URL"))
if page.status_code != 200:
raise Exception("API server not found!")
print(f"GN2 is running. Visit {BLUE}"
f"[http://localhost:{str(port)}/{ENDC}]"
- f"({get_setting('WEBSERVER_URL')})")
+ f"({get_setting(app, 'WEBSERVER_URL')})")