doublerating bug fixed

master
Kostanjevec 2022-08-14 17:34:24 +02:00
parent 8d327690b6
commit e4d68ab719
1 changed files with 24 additions and 27 deletions

View File

@ -158,27 +158,8 @@ def sr_session():
user_id = session['user_id'] user_id = session['user_id']
username = session['username'] username = session['username']
user_settings = get_settings(user_id)
max_new = user_settings["max_new"]
max_due = user_settings["max_due"]
all_new = len(list_of_new_cards_by_ids(user_id)) #form sent?
all_due = len(list_of_due_card_by_ids(user_id))
rated_today_new = rated_today_by_staus("new")
rated_today_due = rated_today_by_staus("due")
#checks if there are any new/due cards left for today and gets the next one. max can be less than all scheduled, min decides which is the limt.
if min(int(max_new), all_new) - int(rated_today_new) > 0:
new_card_id=get_a_card_by_status(user_id, "new")
elif min(int(max_due), all_due) - int(rated_today_due) > 0:
new_card_id=get_a_card_by_status(user_id, "due")
else:
dbsession.close()
flash("no more cards today")
return redirect("/menu")
# Smo oddali obrazec?
if request.method == 'POST': if request.method == 'POST':
#get card_id from the card, rendered from the template, data actually from the template... why tho #get card_id from the card, rendered from the template, data actually from the template... why tho
card_id = request.form.get('card_id', None) card_id = request.form.get('card_id', None)
@ -190,14 +171,12 @@ def sr_session():
# Share # Share
#@@TODO, this should not change the card #@@TODO, this should not change the card
#Share button pressed? then reset the form - hence the if-else
share_request = request.form.get("share", None) share_request = request.form.get("share", None)
if share_request: if share_request:
share(submit_card, user_id) share(submit_card, user_id)
#Rate #Rate
else: else:
rate = request.form.get('rate', None) #is this get somehow dangerous? rate = request.form.get('rate', None)
if not rate: if not rate:
raise Exception("Need rate info!") raise Exception("Need rate info!")
@ -206,8 +185,26 @@ def sr_session():
dbsession.commit() dbsession.commit()
dbsession.close() dbsession.close()
show_card = dbsession.query(Card).get(new_card_id) user_settings = get_settings(user_id)
dbsession.close() max_new = user_settings["max_new"]
max_due = user_settings["max_due"]
all_new = len(list_of_new_cards_by_ids(user_id))
all_due = len(list_of_due_card_by_ids(user_id))
rated_today_new = rated_today_by_staus("new")
rated_today_due = rated_today_by_staus("due")
#checks if there are any new/due cards left for today and gets the next one. max can be more than all scheduled, min decides which is the limt.
if min(int(max_new), all_new) - int(rated_today_new) > 0:
new_card_id=get_a_card_by_status(user_id, "new")
elif min(int(max_due), all_due) - int(rated_today_due) > 0:
new_card_id=get_a_card_by_status(user_id, "due")
else:
dbsession.close()
flash("no more cards today")
return redirect("/menu")
show_card = dbsession.query(Card).get(new_card_id)
#Display from
return render_template("deck.html", username=username, card=show_card) return render_template("deck.html", username=username, card=show_card)