From cfe64eb35b6e24b4ca127cba30ecccd465051d1f Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 8 Jan 2024 05:09:02 +0300 Subject: Implement "POST" path for "select-population" route. --- qc_app/templates/rqtl2/select-population.html | 3 +- qc_app/upload/rqtl2.py | 41 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'qc_app') diff --git a/qc_app/templates/rqtl2/select-population.html b/qc_app/templates/rqtl2/select-population.html index 3ce9dc8..a1e2a83 100644 --- a/qc_app/templates/rqtl2/select-population.html +++ b/qc_app/templates/rqtl2/select-population.html @@ -16,7 +16,8 @@ organised by.

-
+ select grouping/population {{flash_messages("error-select-population")}} diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index aabcea9..f27f0bf 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -6,11 +6,15 @@ from flask import ( url_for, redirect, Blueprint, - render_template) + render_template, + current_app as app) from qc_app.dbinsert import species as all_species -from qc_app.dbinsert import species_by_id, groups_by_species -from qc_app.db_utils import with_db_connection +from qc_app.db_utils import with_db_connection, database_connection +from qc_app.db import ( + species_by_id, + populations_by_species, + population_by_species_and_id) rqtl2 = Blueprint("rqtl2", __name__) @@ -34,15 +38,28 @@ def select_species(): methods=["GET", "POST"]) def select_population(species_id: int): """Select/Create the population to organise data under.""" - species = with_db_connection(lambda conn: species_by_id(conn, species_id)) - if not bool(species): - flash("Invalid species selected!", "alert-error error-rqtl2") - return redirect(url_for("upload.rqtl2.select_species")) + with database_connection(app.config["SQL_URI"]) as conn: + species = species_by_id(conn, species_id) + if not bool(species): + flash("Invalid species selected!", "alert-error error-rqtl2") + return redirect(url_for("upload.rqtl2.select_species")) - if request.method == "GET": - return render_template( - "rqtl2/select-population.html", - species=species, - populations=groups_by_species(species_id)) + if request.method == "GET": + return render_template( + "rqtl2/select-population.html", + species=species, + populations=populations_by_species(conn, species_id)) + + population = population_by_species_and_id( + conn, species["SpeciesId"], request.form.get("inbredset_id")) + if not bool(population): + flash("Invalid Population!", "alert-error error-rqtl2") + return redirect( + url_for("upload.rqtl2.select_population", pgsrc="error"), + code=307) + + return redirect(url_for("upload.rqtl2.upload_rqtl2_bundle", + species_id=species["SpeciesId"], + population_id=population["InbredSetId"])) return "WOULD PROCESS DATA" -- cgit v1.2.3