about summary refs log tree commit diff
path: root/uploader/base_routes.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/base_routes.py')
-rw-r--r--uploader/base_routes.py37
1 files changed, 33 insertions, 4 deletions
diff --git a/uploader/base_routes.py b/uploader/base_routes.py
index 74a3b90..3d0e1b2 100644
--- a/uploader/base_routes.py
+++ b/uploader/base_routes.py
@@ -1,15 +1,23 @@
 """Basic routes required for all pages"""
 import os
+import logging
 from urllib.parse import urljoin
 
-from flask import (Blueprint,
+from gn_libs.mysqldb import database_connection
+from flask import (flash,
+                   request,
+                   url_for,
+                   redirect,
+                   Blueprint,
                    current_app as app,
                    send_from_directory)
 
 from uploader.ui import make_template_renderer
 from uploader.oauth2.client import user_logged_in
+from uploader.species.models import all_species, species_by_id
 
 base = Blueprint("base", __name__)
+logger = logging.getLogger(__name__)
 render_template = make_template_renderer("home")
 
 
@@ -24,9 +32,30 @@ def favicon():
 @base.route("/", methods=["GET"])
 def index():
     """Load the landing page"""
-    return render_template("index.html" if user_logged_in() else "login.html",
-                           gn2server_intro=urljoin(app.config["GN2_SERVER_URL"],
-                                                   "/intro"))
+    streamlined_ui = request.args.get("streamlined_ui")
+    if not bool(streamlined_ui):# TODO: Remove this section
+        return render_template(
+            "index.html" if user_logged_in() else "login.html",
+            gn2server_intro=urljoin(app.config["GN2_SERVER_URL"], "/intro"))
+
+    with database_connection(app.config["SQL_URI"]) as conn:
+        print("We found a species ID. Processing...")
+        if not bool(request.args.get("species_id")):
+            return render_template(
+                "sui-index.html",# TODO: Rename: sui-index.html, sui_base.html
+                gn2server_intro=urljoin(app.config["GN2_SERVER_URL"], "/intro"),
+                species=all_species(conn),
+                streamlined_ui=streamlined_ui)
+
+        species = species_by_id(conn, request.args.get("species_id"))
+        if not bool(species):
+            flash("Selected species was not found!", "alert alert-danger")
+            return redirect(url_for("base.index", streamlined_ui=streamlined_ui))
+
+        return redirect(url_for("species.view_species",
+                                species_id=species["SpeciesId"],
+                                streamlined_ui=streamlined_ui))
+
 
 def appenv():
     """Get app's guix environment path."""