diff --git a/sr_session.py b/sr_session.py index d7fd9c3..7824ff3 100644 --- a/sr_session.py +++ b/sr_session.py @@ -158,27 +158,8 @@ def sr_session(): user_id = session['user_id'] 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)) - 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? + #form sent? if request.method == 'POST': #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) @@ -190,14 +171,12 @@ def sr_session(): # Share #@@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) if share_request: share(submit_card, user_id) #Rate else: - rate = request.form.get('rate', None) #is this get somehow dangerous? - + rate = request.form.get('rate', None) if not rate: raise Exception("Need rate info!") @@ -205,9 +184,27 @@ def sr_session(): dbsession.add(r) dbsession.commit() dbsession.close() + + 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)) + 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) - dbsession.close() - - #Display from - return render_template("deck.html", username=username, card=show_card) + + return render_template("deck.html", username=username, card=show_card) \ No newline at end of file