aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-04-08 09:26:17 +0300
committerFrederick Muriuki Muriithi2024-04-08 09:26:17 +0300
commitd904748a0c8c35d937c6e56fadc7ba52b9f43634 (patch)
treebdf60945cf7a3346123237b156758308bd2f7078
parent7ab16e0fcbc2efe2f446adc52a9df3a900d8561d (diff)
downloadgn-uploader-d904748a0c8c35d937c6e56fadc7ba52b9f43634.tar.gz
bug: Handle IntegrityError: Studies cannot have same name.
-rw-r--r--qc_app/templates/rqtl2/select-probeset-study-id.html7
-rw-r--r--qc_app/upload/rqtl2.py28
2 files changed, 22 insertions, 13 deletions
diff --git a/qc_app/templates/rqtl2/select-probeset-study-id.html b/qc_app/templates/rqtl2/select-probeset-study-id.html
index 23bbbf0..e9a5c13 100644
--- a/qc_app/templates/rqtl2/select-probeset-study-id.html
+++ b/qc_app/templates/rqtl2/select-probeset-study-id.html
@@ -1,5 +1,5 @@
{%extends "base.html"%}
-{%from "flash_messages.html" import flash_messages, flash_all_messages%}
+{%from "flash_messages.html" import flash_messages %}
{%block title%}Upload R/qtl2 Bundle{%endblock%}
@@ -12,13 +12,12 @@
<p>In this page, you can either select from a existing dataset:</p>
</div>
-{{flash_all_messages()}}
-
<form method="POST"
action="{{url_for('upload.rqtl2.select_probeset_study',
species_id=species.SpeciesId, population_id=population.Id)}}"
id="frm:select-probeset-study">
<legend class="heading">Select from existing ProbeSet studies</legend>
+ {{flash_messages("error-rqtl2-select-probeset-study")}}
<input type="hidden" name="species_id" value="{{species.SpeciesId}}" />
<input type="hidden" name="population_id"
@@ -66,6 +65,8 @@
id="frm:create-probeset-study">
<legend class="heading">Create new ProbeSet study</legend>
+ {{flash_messages("error-rqtl2-create-probeset-study")}}
+
<input type="hidden" name="species_id" value="{{species.SpeciesId}}" />
<input type="hidden" name="population_id"
value="{{population.InbredSetId}}" />
diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py
index 860a6a9..e0fb40c 100644
--- a/qc_app/upload/rqtl2.py
+++ b/qc_app/upload/rqtl2.py
@@ -600,29 +600,37 @@ def select_probeset_dataset(species_id: int, population_id: int):
methods=["POST"])
def create_probeset_study(species_id: int, population_id: int):
"""Create a new probeset study."""
+ errorclasses = "alert-error error-rqtl2 error-rqtl2-create-probeset-study"
with database_connection(app.config["SQL_URI"]) as conn:
def __thunk__():
form = request.form
- select_study_page = redirect(
- url_for("upload.rqtl2.select_probeset_study",
+ dataset_info_page = redirect(
+ url_for("upload.rqtl2.select_dataset_info",
species_id=species_id,
population_id=population_id),
code=307)
if not (bool(form.get("platformid")) and
bool(platform_by_id(conn, int(form["platformid"])))):
- flash("Invalid platform selected.", "alert-error error-rqtl2")
- return select_study_page
+ flash("Invalid platform selected.", errorclasses)
+ return dataset_info_page
if not (bool(form.get("tissueid")) and
bool(tissue_by_id(conn, int(form["tissueid"])))):
- flash("Invalid tissue selected.", "alert-error error-rqtl2")
- return select_study_page
+ flash("Invalid tissue selected.", errorclasses)
+ return dataset_info_page
- study = probeset_create_study(
- conn, population_id, int(form["platformid"]), int(form["tissueid"]),
- form["studyname"], form.get("studyfullname") or "",
- form.get("studyshortname") or "")
+ studyname = form["studyname"]
+ try:
+ study = probeset_create_study(
+ conn, population_id, int(form["platformid"]), int(form["tissueid"]),
+ studyname, form.get("studyfullname") or "",
+ form.get("studyshortname") or "")
+ except mdb.IntegrityError as _ierr:
+ flash(f"ProbeSet study with name '{escape(studyname)}' already "
+ "exists.",
+ errorclasses)
+ return dataset_info_page
return render_template(
"rqtl2/create-probe-study-success.html",
species=species_by_id(conn, species_id),