diff options
author | Kristina Hänninen <khannine@local> | 2023-11-21 12:52:55 +0200 |
---|---|---|
committer | Kristina Hänninen <khannine@local> | 2023-11-21 12:52:55 +0200 |
commit | 4c5fd0076b4903320ba470ebf0cd454e5f7a2995 (patch) | |
tree | 8765cb09df85d08b4a6207e0dc959901fddcc4b2 /routes/set/answers.py | |
parent | b868d0ba58384fce5a9a45ae153dee9815327d55 (diff) |
Initial anwsering form and related
Diffstat (limited to 'routes/set/answers.py')
-rw-r--r-- | routes/set/answers.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/routes/set/answers.py b/routes/set/answers.py new file mode 100644 index 0000000..859d65c --- /dev/null +++ b/routes/set/answers.py @@ -0,0 +1,32 @@ +from app import app +from flask import render_template, session, request, redirect +import db_actions as D + +def validate_answer(ans): + if len(ans)<1: + return False + try: + value=int(ans) + if value<0 or value>1000: + return False + except ValueError: + return False + return True + +@app.route("/set/answers",methods=["POST"]) +def set_answers(): + if "id" not in session.keys(): + return "KUOLETTAVA: Nimimerkkiä ei ole vielä valittu!" + if "quiz_id" not in session.keys(): + return "KUOLETTAVA: Yrität vastata kyselyyn ilman sen valintaa!" + + user_id = session["id"] + for id, answer in request.form.items(): + question_id = int(id) + if not validate_answer(answer): + return "KUOLETTAVA: Epäkelpo vastaus!" + if D.get_user_answer(user_id,question_id): + return "KUOLETTAVA: On jo vastattu!" + D.answer_new(user_id, question_id, answer) + + return redirect("/#analyse") |