diff options
author | Frederick Muriuki Muriithi | 2022-07-13 01:27:00 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-07-19 04:59:59 +0300 |
commit | 27032e1876373f9b519275bffbca117f2c96ca1f (patch) | |
tree | 3c79cece5f09854d496f0bc9a0293a4fe3d2f5e6 | |
parent | 45396cacc693a74f7c05a96f814225145dc27ccc (diff) | |
download | gn-uploader-27032e1876373f9b519275bffbca117f2c96ca1f.tar.gz |
Implement study creation
Enable the creation of the new study, and redirect appropriately with
the new study id.
-rw-r--r-- | qc_app/dbinsert.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/qc_app/dbinsert.py b/qc_app/dbinsert.py index 18bc7c2..4fbd0d3 100644 --- a/qc_app/dbinsert.py +++ b/qc_app/dbinsert.py @@ -1,6 +1,7 @@ "Handle inserting data into the database" import os import json +import datetime from functools import reduce import requests @@ -149,9 +150,29 @@ def create_study(): "Create a new study (ProbeFreeze)." form = request.form try: + assert form.get("genechipid"), "platform" assert form.get("studyname"), "study name" assert form.get("inbredsetid"), "group" assert form.get("tissueid"), "type/tissue" + + with database_connection() as conn: + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute("SELECT MAX(Id) AS last_id FROM ProbeFreeze") + new_studyid = cursor.fetchone()["last_id"] + 1 + values = ( + new_studyid, new_studyid, form["genechipid"], + form["tissueid"], form["studyname"], + form.get("studyfullname", ""), + form.get("studyshortname", ""), + datetime.datetime.now().date().strftime("%Y-%m-%d"), + form["inbredsetid"]) + query = ( + "INSERT INTO ProbeFreeze() " + "VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)") + cursor.execute(query, values) + return redirect( + url_for("dbinsert.select_dataset", studyid=new_studyid), + code=307) except AssertionError as aserr: flash(f"Missing data: {aserr.args[0]}", "alert-error") return redirect(url_for("dbinsert.select_study"), code=307) |