aboutsummaryrefslogtreecommitdiff
path: root/uploader/input_validation.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-10-07 13:32:01 -0500
committerFrederick Muriuki Muriithi2024-10-07 13:42:22 -0500
commit4c0186d281ff77b28fa1abe1f84da0e8cb72dea1 (patch)
tree1900f94939deaf3ef49b2122a576bb45e632c231 /uploader/input_validation.py
parent40ae605d358440212a2617d1ec0dddb5f75df5bb (diff)
downloadgn-uploader-4c0186d281ff77b28fa1abe1f84da0e8cb72dea1.tar.gz
Create new phenotype dataset (PublishFreeze).
Provide the UI and code to create a new phenotype dataset.
Diffstat (limited to 'uploader/input_validation.py')
-rw-r--r--uploader/input_validation.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/uploader/input_validation.py b/uploader/input_validation.py
index 88ffd8c..b84fca6 100644
--- a/uploader/input_validation.py
+++ b/uploader/input_validation.py
@@ -1,6 +1,11 @@
"""Input validation utilities"""
+import re
+import json
+import base64
from typing import Any
+from flask import request
+
def is_empty_string(value: str) -> bool:
"""Check whether as string is empty"""
return (isinstance(value, str) and value.strip() == "")
@@ -50,3 +55,19 @@ def is_valid_representative_name(repr_name: str) -> bool:
"""
pattern = re.compile(r"^[a-zA-Z]+[a-zA-Z0-9_-]*[a-zA-Z0-9]$")
return bool(pattern.match(repr_name))
+
+
+def encode_errors(errors: tuple[tuple[str, str], ...], form) -> str:
+ """Encode form errors into base64 string."""
+ return base64.b64encode(
+ json.dumps({
+ "errors": dict(errors),
+ "original_formdata": dict(form)
+ }).encode("utf8"))
+
+
+def decode_errors(errorstr) -> dict[str, dict]:
+ """Decode errors from base64 string"""
+ if not bool(errorstr):
+ return {"errors": {}, "original_formdata": {}}
+ return json.loads(base64.b64decode(errorstr.encode("utf8")).decode("utf8"))