From ad7f0b3cf99ec37be96b819dacd927be86df91ff Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 30 Nov 2023 09:59:14 +0300 Subject: 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. --- qc_app/dbinsert.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'qc_app/dbinsert.py') 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"], -- cgit v1.2.3