aboutsummaryrefslogtreecommitdiff
path: root/qc_app/dbinsert.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-11-30 09:59:14 +0300
committerFrederick Muriuki Muriithi2023-11-30 09:59:14 +0300
commitad7f0b3cf99ec37be96b819dacd927be86df91ff (patch)
tree75e6bb5459617b09aebd5c3481d039caf97b6b9d /qc_app/dbinsert.py
parent3b725c7354b185cc748f1d8ebfac6bab5e17b4aa (diff)
downloadgn-uploader-ad7f0b3cf99ec37be96b819dacd927be86df91ff.tar.gz
Handle duplicate dataset creation error
Notify the user when they try to create a new dataset that has the same name as an existing dataset and give them the chance to fix it before continuing.
Diffstat (limited to 'qc_app/dbinsert.py')
-rw-r--r--qc_app/dbinsert.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/qc_app/dbinsert.py b/qc_app/dbinsert.py
index 4711262..ab1c350 100644
--- a/qc_app/dbinsert.py
+++ b/qc_app/dbinsert.py
@@ -255,10 +255,8 @@ def select_dataset():
studyid = form["studyid"]
datasets = datasets_by_study(studyid)
return render_template(
- "select_dataset.html", filename=form["filename"],
- filetype=form["filetype"], totallines=form["totallines"],
- species=form["species"], genechipid=form["genechipid"],
- studyid=studyid, datasets=datasets, avgmethods=averaging_methods(),
+ "select_dataset.html", **{**form, "studyid": studyid},
+ datasets=datasets, avgmethods=averaging_methods(),
datascales=dataset_datascales())
except AssertionError as aserr:
return render_error(f"Missing data: {aserr.args[0]}")
@@ -283,11 +281,19 @@ def create_dataset():
with database_connection() as conn:
with conn.cursor(cursorclass=DictCursor) as cursor:
+ datasetname = form["datasetname"]
+ cursor.execute("SELECT * FROM ProbeSetFreeze WHERE Name=%s",
+ (datasetname,))
+ results = cursor.fetchall()
+ if bool(results):
+ flash("A dataset with that name already exists.",
+ "alert-error")
+ return redirect(url_for("dbinsert.select_dataset"), code=307)
cursor.execute("SELECT MAX(Id) AS last_id FROM ProbeSetFreeze")
new_datasetid = cursor.fetchone()["last_id"] + 1
values = (
new_datasetid, form["studyid"], form["avgid"],
- form.get("datasetname",""), form["datasetname2"],
+ datasetname, form["datasetname2"],
form["datasetfullname"], form["datasetshortname"],
datetime.now().date().strftime("%Y-%m-%d"),
form["datasetpublic"], form["datasetconfidentiality"],