aboutsummaryrefslogtreecommitdiff
path: root/qc_app
diff options
context:
space:
mode:
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/dbinsert.py21
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)