From e5c44b8714f9f52d218cbb2f70726e845d3fad96 Mon Sep 17 00:00:00 2001 From: Kostanjevec Date: Tue, 16 Aug 2022 10:41:56 +0200 Subject: [PATCH] collecting all functionality related to this in one file --- prob_session.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/prob_session.py b/prob_session.py index 7dc3255..b899a5a 100644 --- a/prob_session.py +++ b/prob_session.py @@ -4,7 +4,10 @@ from share import share """ Refactoring the 'deck' function from app.py + +rabi še deck funkcionalnosti, ki so bile prej v menu.py itd... """ + def prob_session(): dbsession = get_session() if not 'user_id' in session: @@ -92,3 +95,76 @@ def prob_session(): # Prikaži obrazec return render_template("deck.html", username=username, card=show_card) + + + +""" +Old menu function + +def index(): + deck_status = [] + dbsession = get_session() + if 'user_id' not in session: + return login() + + if 'user_id' in session: + user_id = session['user_id'] + username = session['username'] + print(username) + + old_deck = dbsession.query(Deck).filter(Deck.completed == 0, Deck.owner_id == user_id).all() + if old_deck != []: + deck_status = "old" + + if request.method == "POST": + action = request.form.get("menu", False) #internetna rešitev, nevem kako, ampak dela, tj. dobi info iz meni buttonov + print(action) + if action == "new_session": + old_deck = dbsession.query(Deck).filter(Deck.completed == 0, Deck.owner_id == user_id).all() + if old_deck != []: + return redirect(url_for("deck")) + + #preverimo če so sploh karte v collectionu + print("userID", user_id) + c = dbsession.query(Card).filter(Card.owner_id == user_id).all() + + if c == []: + print("ne najdem collectiona") + return render_template("error/no_cards_in_collection.html", username=username) + + #ustvari novi vnos v Deck + user_settings = get_settings(user_id) + if user_settings['max_new'] == "0" and user_settings['max_due'] == "0": + flash("Error: Attempted to make deck with 0 cards.") + return render_template("menu.html") + + deck = probabilistic_deck_generator(user_id, int(user_settings['max_new']), int(user_settings['max_due'])) + cards_by_id = get_deck(deck) + + if cards_by_id == "": + return render_template("error/no_cards_in_collection.html", username=username) + else: + number_of_cards = len(cards_by_id.split(",")) + + print(cards_by_id, number_of_cards) + deck = Deck(cards_by_id=cards_by_id, owner_id=user_id, number_of_cards=number_of_cards, current_card=0, completed=False) + dbsession.add(deck) + dbsession.commit() + dbsession.close() + + return redirect(url_for("deck")) + elif action == "matches": + return redirect(url_for("matches.index")) + elif action == "upload": + return redirect(url_for("upload.index")) + elif action == "settings": + settings = get_settings(user_id) + return render_template("settings.html", username=username, user_id=user_id, settings=settings) + elif action == "instructions": + return render_template("instructions.html", username=username, user_id=user_id) + # elif action == "about": + # return render_template("about.html", username=username, user_id=user_id) + + + return render_template("menu.html", username=username, deck_status=deck_status) +""" \ No newline at end of file