summaryrefslogtreecommitdiff
path: root/routes/set/question.py
diff options
context:
space:
mode:
authorSenni Heidari <sheidar2@local>2023-11-21 11:36:12 +0200
committerSenni Heidari <sheidar2@local>2023-11-21 11:36:12 +0200
commitb868d0ba58384fce5a9a45ae153dee9815327d55 (patch)
tree2d73e810cad9eba76121f28b07eeb49bf3f9e573 /routes/set/question.py
parent2ebfcf29c84b84999b76ff13150ba5a13fd3cac1 (diff)
Update directory hierarchy
Diffstat (limited to 'routes/set/question.py')
-rw-r--r--routes/set/question.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/routes/set/question.py b/routes/set/question.py
new file mode 100644
index 0000000..deaf9be
--- /dev/null
+++ b/routes/set/question.py
@@ -0,0 +1,40 @@
+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
+ return True
+
+def validate_question(question):
+ if len(question)<2:
+ return False
+ return True
+
+@app.route("/set/question",methods=["POST"])
+def new_question():
+ question = request.form["question"]
+ neg_ans = request.form["neg_ans"]
+ pos_ans = request.form["pos_ans"]
+ answer = request.form["answer"]
+ if not validate_question(question):
+ msg = "Kysymys on virheellinen"
+ elif not validate_answer(neg_ans):
+ msg = "Vasen selite on virheellinen"
+ elif not validate_answer(pos_ans):
+ msg = "Oikea selite on virheellinen"
+ elif "id" not in session.keys():
+ msg = "Tarvitaan nimimerkki"
+ elif "quiz_id" not in session.keys():
+ msg = "Ei voi lisätä kysymystä ilman kyselmää"
+ else:
+ quiz_id = session["quiz_id"]
+ user_id = session["id"]
+ question_id = D.question_new( question, neg_ans, pos_ans )
+ D.quiz_add(quiz_id, question_id)
+ D.answer_new(user_id, question_id, answer)
+ return redirect("/#create")
+ session["alert"]="Kysymystä ei luotu: "+msg
+ return redirect("/#create")