about summary refs log tree commit diff
path: root/uploader/phenotypes/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/phenotypes/views.py')
-rw-r--r--uploader/phenotypes/views.py38
1 files changed, 10 insertions, 28 deletions
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index bcbb3a9..dc2df8f 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -31,12 +31,11 @@ from uploader.files import save_file#, fullpath
 from uploader.ui import make_template_renderer
 from uploader.oauth2.client import oauth2_post
 from uploader.authorisation import require_login
+from uploader.route_utils import generic_select_population
+from uploader.datautils import safe_int, enumerate_sequence
 from uploader.species.models import all_species, species_by_id
 from uploader.monadic_requests import make_either_error_handler
 from uploader.request_checks import with_species, with_population
-from uploader.datautils import safe_int, order_by_family, enumerate_sequence
-from uploader.population.models import (populations_by_species,
-                                        population_by_species_and_id)
 from uploader.input_validation import (encode_errors,
                                        decode_errors,
                                        is_valid_representative_name)
@@ -85,31 +84,14 @@ def index():
 @with_species(redirect_uri="species.populations.phenotypes.index")
 def select_population(species: dict, **kwargs):# pylint: disable=[unused-argument]
     """Select the population for your phenotypes."""
-    with database_connection(app.config["SQL_URI"]) as conn:
-        if not bool(request.args.get("population_id")):
-            return render_template("phenotypes/select-population.html",
-                                   species=species,
-                                   populations=populations_by_species(
-                                       conn, species["SpeciesId"]),
-                                   activelink="phenotypes")
-
-        population_id = request.args["population_id"]
-        if population_id == "CREATE-POPULATION":
-            return redirect(url_for(
-                "species.populations.create_population",
-                species_id=species["SpeciesId"],
-                return_to="species.populations.phenotypes.list_datasets"))
-        population = population_by_species_and_id(
-            conn, species["SpeciesId"], int(population_id))
-        if not bool(population):
-            flash("No such population found!", "alert-danger")
-            return redirect(url_for(
-                "species.populations.phenotypes.select_population",
-                species_id=species["SpeciesId"]))
-
-        return redirect(url_for("species.populations.phenotypes.list_datasets",
-                                species_id=species["SpeciesId"],
-                                population_id=population["Id"]))
+    return generic_select_population(
+        species,
+        "phenotypes/select-population.html",
+        request.args.get("population_id") or "",
+        "species.populations.phenotypes.select_population",
+        "species.populations.phenotypes.list_datasets",
+        "phenotypes",
+        "No such population found!")