diff options
author | Frederick Muriuki Muriithi | 2024-01-08 05:09:02 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-01-08 05:52:07 +0300 |
commit | cfe64eb35b6e24b4ca127cba30ecccd465051d1f (patch) | |
tree | 58fbe02235779d22fa9bb5ae1a0ee51a59518dd2 | |
parent | 951c3c2fd343eec4b3743ac313ad6ce49082dda3 (diff) | |
download | gn-uploader-cfe64eb35b6e24b4ca127cba30ecccd465051d1f.tar.gz |
Implement "POST" path for "select-population" route.
-rw-r--r-- | qc_app/templates/rqtl2/select-population.html | 3 | ||||
-rw-r--r-- | qc_app/upload/rqtl2.py | 41 |
2 files changed, 31 insertions, 13 deletions
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.</p> </div> -<form method="POST" action="{{url_for('samples.select_population')}}"> +<form method="POST" + action="{{url_for('upload.rqtl2.select_population', species_id=species.SpeciesId)}}"> <legend class="heading">select grouping/population</legend> {{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" |