diff options
author | Frederick Muriuki Muriithi | 2024-01-08 05:53:18 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-01-08 05:53:18 +0300 |
commit | ea89a07e6d04c2fe58f94839eb9916b365b2f3f2 (patch) | |
tree | c51d3e7c470559a8a3034aa234159a279b00f89b /qc_app | |
parent | cfe64eb35b6e24b4ca127cba30ecccd465051d1f (diff) | |
download | gn-uploader-ea89a07e6d04c2fe58f94839eb9916b365b2f3f2.tar.gz |
Implement "create-population" route.
Diffstat (limited to 'qc_app')
-rw-r--r-- | qc_app/upload/rqtl2.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index f27f0bf..681e54c 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -13,6 +13,7 @@ from qc_app.dbinsert import species as all_species from qc_app.db_utils import with_db_connection, database_connection from qc_app.db import ( species_by_id, + save_population, populations_by_species, population_by_species_and_id) @@ -62,4 +63,36 @@ def select_population(species_id: int): species_id=species["SpeciesId"], population_id=population["InbredSetId"])) - return "WOULD PROCESS DATA" +@rqtl2.route("/upload/species/<int:species_id>/create-population", + methods=["POST"]) +def create_population(species_id: int): + """Create a new population for the given species.""" + population_page = redirect(url_for("upload.rqtl2.select_population")) + with database_connection(app.config["SQL_URI"]) as conn: + species = species_by_id(conn, species_id) + population_name = request.form.get("inbredset_name", "").strip() + population_fullname = request.form.get("inbredset_fullname", "").strip() + if not bool(species): + flash("Invalid species!", "alert-error error-rqtl2") + return redirect(url_for("upload.rqtl2.select_species")) + if not bool(population_name): + flash("Invalid Population Name!", "alert-error error-rqtl2") + return population_page + if not bool(population_fullname): + flash("Invalid Population Full Name!", "alert-error error-rqtl2") + return population_page + new_population = save_population(conn, { + "SpeciesId": species["SpeciesId"], + "Name": population_name, + "InbredSetName": population_fullname, + "FullName": population_fullname, + "Family": request.form.get("inbredset_family") or None, + "Description": request.form.get("description") or None + }) + + flash("Population created successfully.", "alert-success") + return redirect( + url_for("upload.rqtl2.upload_rqtl2_bundle", + population_id=new_population["population_id"], + pgsrc="create-population"), + code=307) |