about summary refs log tree commit diff
path: root/uploader/species/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/species/views.py')
-rw-r--r--uploader/species/views.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/uploader/species/views.py b/uploader/species/views.py
index cea2f68..a490b0f 100644
--- a/uploader/species/views.py
+++ b/uploader/species/views.py
@@ -15,6 +15,8 @@ from uploader.ui import make_template_renderer
 from uploader.oauth2.client import oauth2_get, oauth2_post
 from uploader.authorisation import require_login, require_token
 from uploader.datautils import order_by_family, enumerate_sequence
+from uploader.population.models import (populations_by_species,
+                                        population_by_species_and_id)
 
 from .models import (all_species,
                      save_species,
@@ -41,15 +43,30 @@ def list_species():
 @require_login
 def view_species(species_id: int):
     """View details of a particular species and menus to act upon it."""
+    streamlined_ui = request.args.get("streamlined_ui")
     with database_connection(app.config["SQL_URI"]) as conn:
         species = species_by_id(conn, species_id)
         if bool(species):
-            return render_template("species/view-species.html",
-                                   species=species,
-                                   activelink="view-species")
+            population = population_by_species_and_id(
+                conn, species_id, request.args.get("population_id"))
+            if bool(population):
+                return redirect(url_for("species.populations.view_population",
+                                        species_id=species_id,
+                                        population_id=population["Id"],
+                                        streamlined_ui=streamlined_ui))
+            return render_template(
+                ("species/sui-view-species.html"
+                 if bool(streamlined_ui)
+                 else "species/view-species.html"),
+                species=species,
+                activelink="view-species",
+                streamlined_ui=streamlined_ui,
+                populations=populations_by_species(conn, species["SpeciesId"]))
         flash("Could not find a species with the given identifier.",
               "alert-danger")
-        return redirect(url_for("species.view_species"))
+        return redirect(url_for(
+            ("base.index" if streamlined_ui else "species.view_species"),
+            streamlined_ui=streamlined_ui))
 
 @speciesbp.route("/create", methods=["GET", "POST"])
 @require_login