created blueprint for spaced repetition like deck session
parent
513a28ef51
commit
997fc4eea0
|
@ -0,0 +1,75 @@
|
|||
from flask import session, redirect, url_for, request, render_template
|
||||
|
||||
from share import share
|
||||
from create_db import Card, Rating, get_session
|
||||
|
||||
|
||||
def sr_session():
|
||||
dbsession = get_session()
|
||||
|
||||
#check if user in
|
||||
if not 'user_id' in session:
|
||||
redirect(url_for('login'))
|
||||
user_id = session['user_id']
|
||||
username = session['username']
|
||||
|
||||
|
||||
#koliko je new cards?
|
||||
#koliko je due cards?
|
||||
#ali obstaja naslednji card?
|
||||
#kaj je naslednji card?
|
||||
show_card = ""
|
||||
|
||||
|
||||
#Form sent
|
||||
# Share
|
||||
# Rate
|
||||
|
||||
|
||||
|
||||
# Smo oddali obrazec?
|
||||
if request.method == 'POST':
|
||||
card_id = request.form.get('card_id', None)
|
||||
if not card_id:
|
||||
raise Exception("card_id je nujen!")
|
||||
|
||||
|
||||
submit_card = dbsession.query(Card).get(card_id)
|
||||
# @TODO preveri, ali je card del trenutnega decka!
|
||||
|
||||
# Ali damo share? Potem nastavi na share in ponovi obrazec
|
||||
share_request = request.form.get("share", None)
|
||||
if share_request:
|
||||
# @TODO logika za share!
|
||||
share(submit_card, user_id)
|
||||
|
||||
# Če ne, gre za rate!
|
||||
else:
|
||||
rate = request.form.get('rate', None) #je to nevarno??
|
||||
print(rate)
|
||||
|
||||
if not rate:
|
||||
raise Exception("manjka rate info!")
|
||||
|
||||
if rate == "Yes":
|
||||
submit_card.interest_rate = 1
|
||||
|
||||
elif rate == "Maybe":
|
||||
k = 0.5
|
||||
print(submit_card)
|
||||
submit_card.interest_rate= abs(submit_card.interest_rate*k)
|
||||
|
||||
elif rate == "No":
|
||||
k = 0.1
|
||||
submit_card.interest_rate = abs(submit_card.interest_rate*k)
|
||||
|
||||
elif rate == "Delete":
|
||||
submit_card.interest_rate = 0
|
||||
#@TODO to bi lahko zbrisalo tudi file v določenih primerih
|
||||
|
||||
# Any more cards?
|
||||
|
||||
# Loudamo naslednjo karto
|
||||
|
||||
# Prikaži obrazec
|
||||
return render_template("deck/index.html", username=username, card=show_card)
|
Loading…
Reference in New Issue