summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.py2
-rw-r--r--routes/analyse.py20
-rw-r--r--routes/answer.py20
-rw-r--r--routes/base.py6
-rw-r--r--routes/create.py12
-rw-r--r--routes/question.py8
-rw-r--r--routes/tools.py4
-rw-r--r--static/alert-timeout.js14
-rw-r--r--static/kys-link-info.js12
9 files changed, 53 insertions, 45 deletions
diff --git a/app.py b/app.py
index a50dc30..ce1e1fb 100644
--- a/app.py
+++ b/app.py
@@ -15,7 +15,7 @@ else:
app.secret_key = token_hex()
from db.db import DB
-D = DB()
+db = DB()
import routes.base
import routes.answer
diff --git a/routes/analyse.py b/routes/analyse.py
index f982f2e..0686674 100644
--- a/routes/analyse.py
+++ b/routes/analyse.py
@@ -1,16 +1,16 @@
from itertools import combinations
-from app import app, D
+from app import app, db
from flask import render_template,session,request,redirect
from routes.tools import rows2dicts, get_alert, get_nick, csrf_check
def find_best_and_worst(aid, uid):
match = {}
- comb = D.analyse.combinations(aid)
+ comb = db.analyse.combinations(aid)
if len(comb)<1:
comb=[(uid,uid)]
min, minme, max, maxme = 101, 101, -1, -1
for pair in comb:
- match[pair] = int(D.analyse.compare(aid,pair[0],pair[1]))
+ match[pair] = int(db.analyse.compare(aid,pair[0],pair[1]))
if match[pair] < min:
min = match[pair]
min_pair = pair
@@ -42,7 +42,7 @@ def analyse():
alert=get_alert()
)
- if "answer_id" in session and D.quiz.user(session["answer_id"],sid):
+ if "answer_id" in session and db.quiz.user(session["answer_id"],sid):
aid = session["answer_id"]
else:
return render_template(
@@ -53,10 +53,10 @@ def analyse():
)
uid1 = session["anal_user1"] if "anal_user1" in session else sid
- uid1 = sid if uid1 != sid and not D.quiz.user(aid,uid1) else uid1
+ uid1 = sid if uid1 != sid and not db.quiz.user(aid,uid1) else uid1
uid2 = session["anal_user2"] if "anal_user2" in session else sid
- uid2 = sid if uid2 != sid and not D.quiz.user(aid,uid2) else uid2
+ uid2 = sid if uid2 != sid and not db.quiz.user(aid,uid2) else uid2
best = find_best_and_worst(aid, sid)
@@ -70,13 +70,13 @@ def analyse():
caller="analyse",
alert=get_alert(),
nick=get_nick(),
- code=D.quiz.get_link(aid),
- questions = rows2dicts( D.analyse.pagedata( aid, uid1, uid2 ),
+ code=db.quiz.get_link(aid),
+ questions = rows2dicts( db.analyse.pagedata( aid, uid1, uid2 ),
['q','n','p','a1','a2','c'] ),
- users = rows2dicts( D.quiz.users(aid), ['id','nick'] ),
+ users = rows2dicts( db.quiz.users(aid), ['id','nick'] ),
user1=int(uid1),
user2=int(uid2),
- avg = int(D.analyse.compare(aid,uid1,uid2)),
+ avg = int(db.analyse.compare(aid,uid1,uid2)),
best = best
)
diff --git a/routes/answer.py b/routes/answer.py
index 2c2be82..62c2f2f 100644
--- a/routes/answer.py
+++ b/routes/answer.py
@@ -1,11 +1,11 @@
-from app import app, D
+from app import app, db
from flask import render_template, session, request, redirect
from routes.tools import rows2dicts, get_alert, get_nick, csrf_check
@app.route("/kys/<link>")
def kys_link(link):
- if aid := D.quiz.find_by_link( link ):
+ if aid := db.quiz.find_by_link( link ):
session["answer_id"] = aid
return redirect("/#answer")
return redirect("/")
@@ -25,18 +25,18 @@ def answer_id():
session["alert"] = "Kyselmän nimeä ei ole annettu."
return redirect(next)
- if aid := D.quiz.find_by_link( request.form["link"] ):
+ if aid := db.quiz.find_by_link( request.form["link"] ):
session["answer_id"] = aid
else:
session["alert"] = "Koodilla ei löytynyt kyselmää"
return redirect(next)
- if next == "/#analyse" and not D.quiz.user( aid, sid ):
+ if next == "/#analyse" and not db.quiz.user( aid, sid ):
session["alert"] = "Et ole vielä vastannut tähän kyselmään. \
Voit tutkia vastaksia vastattuasi."
return redirect("/#answer")
- if next == "/#answer" and D.quiz.user( aid, sid ):
+ if next == "/#answer" and db.quiz.user( aid, sid ):
session["alert"] = "Olet jo vastannut valitsemaasi kyselyyn."
return redirect("/#analyse")
@@ -63,7 +63,7 @@ def answer():
nick = get_nick()
)
- if D.quiz.user(aid, sid):
+ if db.quiz.user(aid, sid):
return render_template(
"answer.html",
caller = "answer",
@@ -76,8 +76,8 @@ def answer():
caller = "answer",
alert = get_alert(),
nick = get_nick(),
- questions = rows2dicts( D.quiz.questions(aid), ['i','q','n','p'] ),
- link = D.quiz.get_link( aid )
+ questions = rows2dicts( db.quiz.questions(aid), ['i','q','n','p'] ),
+ link = db.quiz.get_link( aid )
)
@app.route("/set/answers",methods=["POST"])
@@ -99,7 +99,7 @@ def set_answers():
if int(answer) < 0 or int(answer) > 999:
session["alert"]="Luvattoman pieniä tai suuria lukuja!"
return redirect( "/#answer" )
- elif D.answer.get(int(sid), int(question)) != -1:
+ elif db.answer.get(int(sid), int(question)) != -1:
session["alert"]="Kyselyyn olikin jo saatu vastauksia."
return redirect( "/#answer" )
except ValueError:
@@ -109,6 +109,6 @@ def set_answers():
for question, answer in request.form.items():
if question=="csrf":
continue
- D.answer.new(int(sid), int(question), int(answer))
+ db.answer.new(int(sid), int(question), int(answer))
return redirect("/#analyse")
diff --git a/routes/base.py b/routes/base.py
index a9c0e19..52db258 100644
--- a/routes/base.py
+++ b/routes/base.py
@@ -1,5 +1,5 @@
from secrets import token_urlsafe
-from app import app, D
+from app import app, db
from flask import render_template,session,request,redirect
from routes.tools import rows2dicts, get_alert, get_nick, csrf_check
@@ -42,10 +42,10 @@ def new_nick():
if not nick.isalnum():
session["alert"]="Nimimerkissä saa olla vain kirjaimia ja numeroita."
return redirect(next)
- if D.user.exists(nick):
+ if db.user.exists(nick):
session["alert"]="Nimimerkki jonka olet ottamassa on jo varattu."
return redirect(next)
- session["id"] = int(D.user.new(nick))
+ session["id"] = int(db.user.new(nick))
return redirect(next)
diff --git a/routes/create.py b/routes/create.py
index d2701a2..f584543 100644
--- a/routes/create.py
+++ b/routes/create.py
@@ -1,4 +1,4 @@
-from app import app, D
+from app import app, db
from flask import render_template,session,request,redirect
from routes.tools import rows2dicts, get_alert, get_nick, generate_link, csrf_check
@@ -18,7 +18,7 @@ def create():
alert=get_alert(),
nick=get_nick()
)
- if D.quiz.get_link(session["quiz_id"]):
+ if db.quiz.get_link(session["quiz_id"]):
return render_template(
"create.html",
caller="create",
@@ -33,7 +33,7 @@ def create():
nick=get_nick(),
quiz_set=True,
questions=rows2dicts(
- D.quiz.questions(session["quiz_id"]),
+ db.quiz.questions(session["quiz_id"]),
['i','q','n','p','a']
)
)
@@ -46,7 +46,7 @@ def new_quiz():
session["alert"]="Tarvitset nimimerkin loudaksesi."
return redirect("/#create")
user_id = session["id"]
- session["quiz_id"] = D.quiz.new( user_id )
+ session["quiz_id"] = db.quiz.new( user_id )
return redirect("/#create")
@@ -57,10 +57,10 @@ def quiz_ready():
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"]):
+ if not db.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())
+ db.quiz.set_link(session["quiz_id"], generate_link())
return redirect("/#analyse")
diff --git a/routes/question.py b/routes/question.py
index a56c0db..b9c45c8 100644
--- a/routes/question.py
+++ b/routes/question.py
@@ -1,4 +1,4 @@
-from app import app, D
+from app import app, db
from flask import render_template,session,request,redirect
from routes.tools import rows2dicts, get_alert, get_nick, csrf_check
@@ -45,8 +45,8 @@ def new_question():
session["alert"] = "Vastauksessasi on nyt jotain häikkää."
return redirect("/#question")
- question_id = D.question.new( question, neg_ans, pos_ans )
- D.quiz.add(qid, question_id)
- D.answer.new(sid, question_id, answer)
+ question_id = db.question.new( question, neg_ans, pos_ans )
+ db.quiz.add(qid, question_id)
+ db.answer.new(sid, question_id, answer)
return redirect("/#create")
diff --git a/routes/tools.py b/routes/tools.py
index 65aff62..3a5e68e 100644
--- a/routes/tools.py
+++ b/routes/tools.py
@@ -1,6 +1,6 @@
from random import randint
from flask import session, request
-from app import D
+from app import db
def rows2dicts( rows, names ):
dlist=[]
@@ -20,7 +20,7 @@ def get_alert():
def get_nick():
while "id" in session.keys():
- nick = D.user.get_nick(session["id"])
+ nick = db.user.get_nick(session["id"])
if not nick:
del session['id']
if "quiz_id" in session.keys():
diff --git a/static/alert-timeout.js b/static/alert-timeout.js
index e20106f..b31d461 100644
--- a/static/alert-timeout.js
+++ b/static/alert-timeout.js
@@ -1,8 +1,12 @@
setInterval( () => {
- Array.from(document.getElementsByClassName('kysAlert')).forEach( (a)=>{
+ Array.from(document.getElementsByClassName('kysAlert')).forEach( (a) => {
a.addEventListener('click', (event) => { event.target.remove() } )
- if (a.style.transition=="opacity 2s") a.remove()
- a.style.transition="opacity 2s"
- a.style.opacity=0;
+ if ( a.state == undefined ) a.state = 0
+ if (a.state == 4) {
+ a.style.transition = "opacity 1s"
+ a.style.opacity = 0
+ }
+ if (a.state == 5) a.remove()
+ a.state += 1
} )
-}, 5000)
+}, 1000)
diff --git a/static/kys-link-info.js b/static/kys-link-info.js
index f3165b2..18a0a23 100644
--- a/static/kys-link-info.js
+++ b/static/kys-link-info.js
@@ -13,8 +13,12 @@ kysLink.onclick = () => {
setInterval( () => {
Array.from(document.getElementsByClassName('kysInfo')).forEach( (a)=>{
a.addEventListener('click', (event) => { event.target.remove() } )
- if (a.style.transition=="opacity 2s") a.remove()
- a.style.transition="opacity 2s"
- a.style.opacity=0;
+ if ( a.state == undefined ) a.state = 0
+ if (a.state == 4) {
+ a.style.transition = "opacity 1s"
+ a.style.opacity = 0
+ }
+ if (a.state == 5) a.remove()
+ a.state += 1
} )
-}, 5000)
+}, 1000)