aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2022-08-06 20:46:55 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2022-08-06 20:46:55 +0200
commit71a94b17713e945b4e27dc051591127a7d4c8478 (patch)
tree0ea25675d04a7f8bd69b168a33bf85fededda17c
parentfix pdf extension upper case (diff)
downloadscout-subs-71a94b17713e945b4e27dc051591127a7d4c8478.tar.gz
scout-subs-71a94b17713e945b4e27dc051591127a7d4c8478.zip
fix incorect parsing of approval code
-rw-r--r--server/views.py22
-rw-r--r--version.txt2
2 files changed, 19 insertions, 5 deletions
diff --git a/server/views.py b/server/views.py
index a54c588..7643bee 100644
--- a/server/views.py
+++ b/server/views.py
@@ -123,10 +123,9 @@ def uapprove(request):
# parse text to array
data = request.POST["codes"]
- data = data.split("\n")
+ data = split_codes(data)
# check if format is right
for i in range(len(data)):
- data[i] = data[i].replace("\r", "")
if not data[i].startswith("U"):
data[i] = data[i] + " - Formato errato"
elif not data[i][1:].isdigit():
@@ -159,6 +158,22 @@ def uapprove(request):
return render(request, 'server/approve_user.html', context)
+def split_codes(str):
+ out = []
+ buffer = ""
+ for i in str:
+ if i.isdigit() or i == "U":
+ buffer += i
+ continue
+
+ if i == "\n":
+ out.append(buffer)
+ buffer = ""
+
+ if buffer != "":
+ out.append(buffer)
+
+ return out
@user_passes_test(isStaff)
def docapprove(request):
@@ -174,8 +189,7 @@ def docapprove(request):
if request.method == "POST":
# parse text in array
data = request.POST["codes"]
- data.replace("\r", "")
- data = data.split("\n")
+ data = split_codes(data)
# check if code valid
for i in range(len(data)):
if not data[i].isdigit():
diff --git a/version.txt b/version.txt
index bf156bd..83dd6d8 100644
--- a/version.txt
+++ b/version.txt
@@ -1,2 +1,2 @@
version=0.5
-rev=35
+rev=36