blob: e7494bc2e6d95bd2e866291bd97fbc39d86da9aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
from app import app
from flask import render_template, session, request, redirect
import db_actions as D
def validate_answer(ans):
return True
def validate_question(question):
return True
@app.route("/new_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 virheellinen"
elif not validate_answer(pos_ans):
msg = "Oikea selite 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")
|