about summary refs log tree commit diff
path: root/uploader/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/__init__.py')
-rw-r--r--uploader/__init__.py43
1 files changed, 37 insertions, 6 deletions
diff --git a/uploader/__init__.py b/uploader/__init__.py
index 98e8141..e00c726 100644
--- a/uploader/__init__.py
+++ b/uploader/__init__.py
@@ -11,7 +11,7 @@ from cachelib import FileSystemCache
 
 from gn_libs import jobs as gnlibs_jobs
 
-from flask_session import Session
+from flask_session import Session# type: ignore[attr-defined]
 
 
 from uploader.oauth2.client import user_logged_in, authserver_authorise_uri
@@ -22,6 +22,7 @@ from .files.views import files
 from .species import speciesbp
 from .publications import pubbp
 from .oauth2.views import oauth2
+from .flask_extensions import url_for
 from .expression_data import exprdatabp
 from .errors import register_error_handlers
 from .background_jobs import background_jobs_bp
@@ -72,6 +73,28 @@ def setup_modules_logging(app_logger, modules):
         _logger.setLevel(loglevel)
 
 
+def __setup_scratch_directory__(app: Flask) -> Flask:
+    app.config["SCRATCH_DIRECTORY"] = Path(
+        app.config["SCRATCH_DIRECTORY"]).absolute()
+    return app
+
+def __setup_upload_directory__(app: Flask) -> Flask:
+    if app.config.get("UPLOADS_DIRECTORY", "").strip() == "":
+        app.config["UPLOADS_DIRECTORY"] = app.config[
+            "SCRATCH_DIRECTORY"].joinpath("uploads")
+    else:
+        app.config["UPLOADS_DIRECTORY"] = Path(
+            app.config["UPLOADS_DIRECTORY"].strip()).absolute()
+
+    return app
+
+
+def update_unspecified_defaults(app: Flask) -> Flask:
+    """Setup the defaults for necessary configurations that do not have values
+    specified for them."""
+    return __setup_upload_directory__(__setup_scratch_directory__(app))
+
+
 def create_app(config: Optional[dict] = None):
     """The application factory.
 
@@ -99,26 +122,34 @@ def create_app(config: Optional[dict] = None):
             # Silently ignore secrets if the file does not exist.
             app.config.from_pyfile(secretsfile)
     app.config.update(config) # Override everything with passed in config
+    update_unspecified_defaults(app)
     ### END: Application configuration
 
     app.config["SESSION_CACHELIB"] = FileSystemCache(
-        cache_dir=Path(app.config["SESSION_FILESYSTEM_CACHE_PATH"]).absolute(),
+        cache_dir=str(Path(app.config["SESSION_FILESYSTEM_CACHE_PATH"]).absolute()),
         threshold=int(app.config["SESSION_FILESYSTEM_CACHE_THRESHOLD"]),
         default_timeout=int(app.config["SESSION_FILESYSTEM_CACHE_TIMEOUT"]))
 
     setup_logging(app)
     setup_modules_logging(app.logger, (
+        "uploader.base_routes",
+        "uploader.flask_extensions",
         "uploader.publications.models",
         "uploader.publications.datatables",
-        "uploader.phenotypes.models"))
+        "uploader.phenotypes.models",
+        "uploader.phenotypes.views"))
 
     # setup jinja2 symbols
-    app.add_template_global(lambda : request.url, name="request_url")
+    app.add_template_global(user_logged_in)
+    app.add_template_global(url_for, name="url_for")
     app.add_template_global(authserver_authorise_uri)
+    app.add_template_global(lambda : request.url, name="request_url")
     app.add_template_global(lambda: app.config["GN2_SERVER_URL"],
                             name="gn2server_uri")
-    app.add_template_global(user_logged_in)
-    app.add_template_global(lambda : session.user_details()["email"], name="user_email")
+    app.add_template_global(lambda : session.user_details()["email"],
+                            name="user_email")
+    app.add_template_global(lambda: app.config["FEATURE_FLAGS_HTTP"],
+                            name="http_feature_flags")
 
     Session(app)