From 3c960f6cf885934e5f390390c9e0fae0d6b93d5d Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 18 Feb 2025 11:10:29 -0600 Subject: Enable creating new populations on the "Phenotype Data" path. Enable creating new populations in the case where the population a user wants to use does not exist in the database. --- uploader/phenotypes/views.py | 14 ++++-- uploader/population/views.py | 12 ++++- .../templates/phenotypes/select-population.html | 20 +++++--- .../templates/populations/create-population.html | 5 +- .../populations/macro-select-population.html | 55 ++++++++++++---------- 5 files changed, 67 insertions(+), 39 deletions(-) diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py index c0ab493..bcbb3a9 100644 --- a/uploader/phenotypes/views.py +++ b/uploader/phenotypes/views.py @@ -89,14 +89,18 @@ def select_population(species: dict, **kwargs):# pylint: disable=[unused-argumen if not bool(request.args.get("population_id")): return render_template("phenotypes/select-population.html", species=species, - populations=order_by_family( - populations_by_species( - conn, species["SpeciesId"]), - order_key="FamilyOrder"), + 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(request.args["population_id"])) + conn, species["SpeciesId"], int(population_id)) if not bool(population): flash("No such population found!", "alert-danger") return redirect(url_for( diff --git a/uploader/population/views.py b/uploader/population/views.py index 4f985f5..1ece35f 100644 --- a/uploader/population/views.py +++ b/uploader/population/views.py @@ -5,6 +5,7 @@ import base64 from MySQLdb.cursors import DictCursor from gn_libs.mysqldb import database_connection from flask import (flash, + escape, request, url_for, redirect, @@ -101,6 +102,7 @@ def create_population(species_id: int): {"id": "2", "value": "GEMMA"}, {"id": "3", "value": "R/qtl"}, {"id": "4", "value": "GEMMA, PLINK"}), + return_to=(request.args.get("return_to") or ""), activelink="create-population", **error_values) @@ -151,7 +153,15 @@ def create_population(species_id: int): }) def __flash_success__(_success): - flash("Successfully created resource.", "alert-success") + flash("Successfully created population " + f"{escape(new_population['FullName'])}.", + "alert-success") + return_to = request.form.get("return_to") or "" + if return_to: + return redirect(url_for( + return_to, + species_id=species["SpeciesId"], + population_id=new_population["InbredSetId"])) return redirect(url_for( "species.populations.view_population", species_id=species["SpeciesId"], diff --git a/uploader/templates/phenotypes/select-population.html b/uploader/templates/phenotypes/select-population.html index eafd4a7..d6e6aa1 100644 --- a/uploader/templates/phenotypes/select-population.html +++ b/uploader/templates/phenotypes/select-population.html @@ -11,18 +11,24 @@ {%block contents%} {{flash_all_messages()}} -
-

Select the population for your phenotypes to view and manage the phenotype - datasets that relate to it.

-
- {{select_population_form(url_for("species.populations.phenotypes.select_population", - species_id=species.SpeciesId), - populations)}} + {{select_population_form(url_for("species.populations.phenotypes.select_population", species_id=species.SpeciesId), species, populations)}}
{%endblock%} {%block sidebarcontents%} {{display_species_card(species)}} {%endblock%} + +{%block javascript%} + + + +{%endblock%} diff --git a/uploader/templates/populations/create-population.html b/uploader/templates/populations/create-population.html index 86aebda..c0c4f45 100644 --- a/uploader/templates/populations/create-population.html +++ b/uploader/templates/populations/create-population.html @@ -37,12 +37,15 @@
+ species_id=species.SpeciesId, + return_to=return_to)}}"> Create Population {{flash_all_messages()}} + +
- Select Population -
- -
- -
+ {%if populations | length != 0%} + + + + + + + + + + + +
Population
+ +
+
+ {%else%} +

+ There are no populations currently defined for {{species['FullName']}} + ({{species['SpeciesName']}}).
+ Click "Continue" to create the first!

+ + {%endif%} +
- +
{%endmacro%} -- cgit v1.2.3