interval ui stuff and prob_deck removal

master
Kostanjevec 2022-08-16 10:50:03 +02:00
parent ef1ba946c0
commit a9f2a75442
1 changed files with 7 additions and 38 deletions

45
menu.py
View File

@ -1,9 +1,8 @@
from flask import ( from flask import (
Blueprint, flash, redirect, render_template, request, session, url_for Blueprint, flash, redirect, render_template, request, session, url_for
) )
from create_db import Card, get_session
from create_db import Deck, Card, get_session from sr_session import remaining_by_status, schedule_status
from deck import get_deck, probabilistic_deck_generator
from settings import get_settings from settings import get_settings
from auth import login from auth import login
@ -11,7 +10,6 @@ bp = Blueprint('menu', __name__, url_prefix='/menu')
@bp.route("/", methods=("GET", "POST")) @bp.route("/", methods=("GET", "POST"))
def index(): def index():
deck_status = []
dbsession = get_session() dbsession = get_session()
if 'user_id' not in session: if 'user_id' not in session:
return login() return login()
@ -20,48 +18,22 @@ def index():
user_id = session['user_id'] user_id = session['user_id']
username = session['username'] username = session['username']
print(username) print(username)
status = schedule_status(user_id)
old_deck = dbsession.query(Deck).filter(Deck.completed == 0, Deck.owner_id == user_id).all() remaining_new = remaining_by_status(user_id, "new")
if old_deck != []: remaining_due = remaining_by_status(user_id, "due")-remaining_new
deck_status = "old"
if request.method == "POST": if request.method == "POST":
action = request.form.get("menu", False) #internetna rešitev, nevem kako, ampak dela, tj. dobi info iz meni buttonov action = request.form.get("menu", False) #internetna rešitev, nevem kako, ampak dela, tj. dobi info iz meni buttonov
print(action) print(action)
if action == "new_session": 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 #preverimo če so sploh karte v collectionu
print("userID", user_id) print("userID", user_id)
c = dbsession.query(Card).filter(Card.owner_id == user_id).all() c = dbsession.query(Card).filter(Card.owner_id == user_id).all()
if c == []: if c == []:
print("ne najdem collectiona") print("ne najdem collectiona")
return render_template("error/no_cards_in_collection.html", username=username) 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 redirect(url_for("deck"))
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": elif action == "matches":
return redirect(url_for("matches.index")) return redirect(url_for("matches.index"))
elif action == "upload": elif action == "upload":
@ -71,8 +43,5 @@ def index():
return render_template("settings.html", username=username, user_id=user_id, settings=settings) return render_template("settings.html", username=username, user_id=user_id, settings=settings)
elif action == "instructions": elif action == "instructions":
return render_template("instructions.html", username=username, user_id=user_id) 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=status, remaining_due=remaining_due, remaining_new=remaining_new)
return render_template("menu.html", username=username, deck_status=deck_status)