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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
from app import app, D
from flask import render_template,session,request,redirect
from routes.tools import rows2dicts, get_alert, get_nick, generate_link, csrf_check
@app.route("/pages/create.html")
def create():
if "id" not in session:
return render_template(
"create.html",
caller="create",
alert=get_alert()
)
if "quiz_id" not in session:
return render_template(
"create.html",
caller="create",
alert=get_alert(),
nick=get_nick()
)
if D.quiz.get_link(session["quiz_id"]):
return render_template(
"create.html",
caller="create",
alert=get_alert(),
nick=get_nick()
)
return render_template(
"create.html",
caller="create",
alert=get_alert(),
nick=get_nick(),
quiz_set=True,
questions=rows2dicts(
D.quiz.questions(session["quiz_id"]),
['i','q','n','p','a']
)
)
@app.route("/set/quiz",methods=["POST"])
def new_quiz():
if csrf_check():
return redirect("/#create")
if not "id" in session.keys():
session["alert"]="Tarvitset nimimerkin loudaksesi."
return redirect("/#create")
user_id = session["id"]
session["quiz_id"] = D.quiz.new( user_id )
return redirect("/#create")
@app.route("/set/quiz_ready",methods=["POST"])
def quiz_ready():
if csrf_check():
return redirect("/#create")
if "quiz_id" not in session.keys():
session["alert"] = "Kyselmä jota ei ole aloitettu ei voi olla valmis."
return redirect("/#create")
if not D.quiz.user(session["quiz_id"], session["id"]):
session["alert"] = "Tyhjän kyselmän luominen ei käy päinsä!"
return redirect("/#create")
quiz_id = session["quiz_id"]
session["answer_id"] = session["quiz_id"]
D.quiz.set_link(session["quiz_id"], generate_link())
return redirect("/#analyse")
|