diff options
Diffstat (limited to 'routes/set')
-rw-r--r-- | routes/set/answers.py | 32 | ||||
-rw-r--r-- | routes/set/nick.py | 28 | ||||
-rw-r--r-- | routes/set/question.py | 40 | ||||
-rw-r--r-- | routes/set/quiz.py | 13 |
4 files changed, 0 insertions, 113 deletions
diff --git a/routes/set/answers.py b/routes/set/answers.py deleted file mode 100644 index 859d65c..0000000 --- a/routes/set/answers.py +++ /dev/null @@ -1,32 +0,0 @@ -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") diff --git a/routes/set/nick.py b/routes/set/nick.py deleted file mode 100644 index 67ddeea..0000000 --- a/routes/set/nick.py +++ /dev/null @@ -1,28 +0,0 @@ -from app import app -from flask import render_template, session, request, redirect -import db_actions as D - - -@app.route("/set/nick",methods=["POST"]) -def new_nick(): - nick = request.form["nick"] - if "id" in session.keys(): - msg = "You already have a nick." - elif D.user_exists(nick): - msg = "Nick is already reserved." - elif msg := invalid_nick(nick): - pass - else: - session["id"] = D.user_new(nick) - return redirect("/") - session["alert"]="Nick in not created: "+msg - return redirect("/#nick") - - -def invalid_nick(nick): - if len(nick)<4: - return "Nick is too short" - if not nick.isalnum(): - return "Only letters and numbers are allowed" - return 0 -
\ No newline at end of file diff --git a/routes/set/question.py b/routes/set/question.py deleted file mode 100644 index deaf9be..0000000 --- a/routes/set/question.py +++ /dev/null @@ -1,40 +0,0 @@ -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") diff --git a/routes/set/quiz.py b/routes/set/quiz.py deleted file mode 100644 index 9ad13da..0000000 --- a/routes/set/quiz.py +++ /dev/null @@ -1,13 +0,0 @@ -from app import app -from flask import render_template, session, request, redirect -import db_actions as D - - -@app.route("/set/quiz",methods=["POST"]) -def new_quiz(): - if not "id" in session.keys(): - session["alert"]="Tarvitset nimimerkin loudaksesi" - return redirect("/#nick") - user_id = session["id"] - session["quiz_id"] = D.quiz_new( user_id ) - return redirect("/#create") |