aboutsummaryrefslogtreecommitdiff
path: root/uploader/population
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-05 12:50:52 -0500
committerFrederick Muriuki Muriithi2024-09-05 14:19:47 -0500
commitb6a38df0eaedb9ac4bb4b602643ca1e97f889b49 (patch)
treeea7deda3ea4bd4c3388df91091060b50cc2162dc /uploader/population
parentf5b60f2909c6683345ae0f1070e84e40c41af5ad (diff)
downloadgn-uploader-b6a38df0eaedb9ac4bb4b602643ca1e97f889b49.tar.gz
Improve error messaging for "Create Population" feature.
Diffstat (limited to 'uploader/population')
-rw-r--r--uploader/population/views.py43
1 files changed, 23 insertions, 20 deletions
diff --git a/uploader/population/views.py b/uploader/population/views.py
index fe318e1..84dffdb 100644
--- a/uploader/population/views.py
+++ b/uploader/population/views.py
@@ -90,46 +90,49 @@ def create_population(species_id: int):
if request.method == "GET":
error_values = request.args.get("error_values")
- if bool(error_values):
- base64.b64encode(
- json.dumps(dict(request.form)).encode("utf8"))
- error_values = json.loads(
- base64.b64decode(
- error_values.encode("utf8")).decode("utf8"))
+ if not bool(error_values):
+ error_values = base64.b64encode(
+ '{"errors":{}, "error_values": {}}'.encode("utf8")
+ ).decode("utf8")
+
+ error_values = json.loads(base64.b64decode(
+ error_values.encode("utf8")).decode("utf8"))
return render_template(
"populations/create-population.html",
species=species,
activelink="create-population",
**error_values)
- error = False
-
if not bool(species):
flash("You must select a species.", "alert-danger")
- error = True
+ return redirect(url_for("species.populations.index"))
+
+ errors = tuple()
population_name = (request.form.get(
"population_name") or "").strip()
if not bool(population_name):
- flash("You must provide a name for the population!", "alert-danger")
- error = True
+ errors = errors + (("population_name",
+ "You must provide a name for the population!"),)
if not valid_population_name(population_name):
- flash("The population name can only contain letters, numbers, "
- "hyphens and underscores.",
- "alert-danger")
- error = True
+ errors = errors + ((
+ "population_name",
+ "The population name can only contain letters, numbers, "
+ "hyphens and underscores."),)
population_fullname = (request.form.get(
"population_fullname") or "").strip()
if not bool(population_fullname):
- flash("You MUST provide a Full Name for the population.",
- "alert-danger")
- error = True
+ errors = errors + (
+ ("population_fullname", "Full Name MUST be provided."),)
- if error:
+ if bool(errors):
values = base64.b64encode(
- json.dumps(dict(request.form)).encode("utf8"))
+ json.dumps({
+ "errors": dict(errors),
+ "error_values": dict(request.form)
+ }).encode("utf8"))
return redirect(url_for("species.populations.create_population",
species_id=species["SpeciesId"],
error_values=values))