2022-06-04 21:58:05 +02:00
|
|
|
from flask import (
|
2022-10-31 17:40:25 +01:00
|
|
|
Blueprint, redirect, render_template, request, session, url_for
|
2022-06-04 21:58:05 +02:00
|
|
|
)
|
2022-08-16 10:50:03 +02:00
|
|
|
from create_db import Card, get_session
|
2022-10-31 17:40:25 +01:00
|
|
|
from sr_session import schedule_status, remaining_items, list_of_due_cards_by_ids, list_of_new_cards_by_ids, rated_today_by_staus
|
2022-06-23 14:39:16 +02:00
|
|
|
from settings import get_settings
|
2022-06-14 02:26:38 +02:00
|
|
|
from auth import login
|
2022-06-04 21:58:05 +02:00
|
|
|
|
|
|
|
bp = Blueprint('menu', __name__, url_prefix='/menu')
|
|
|
|
|
|
|
|
@bp.route("/", methods=("GET", "POST"))
|
|
|
|
def index():
|
2022-06-14 14:47:12 +02:00
|
|
|
dbsession = get_session()
|
2022-06-14 02:26:38 +02:00
|
|
|
if 'user_id' not in session:
|
|
|
|
return login()
|
|
|
|
|
2022-06-04 21:58:05 +02:00
|
|
|
if 'user_id' in session:
|
|
|
|
user_id = session['user_id']
|
|
|
|
username = session['username']
|
|
|
|
print(username)
|
2022-08-16 10:50:03 +02:00
|
|
|
status = schedule_status(user_id)
|
2022-10-31 17:40:25 +01:00
|
|
|
|
|
|
|
user_settings = get_settings(user_id)
|
|
|
|
max_new = int(user_settings["max_new"])
|
|
|
|
max_due = int(user_settings["max_due"])
|
|
|
|
|
|
|
|
total_new = len(list_of_new_cards_by_ids(user_id))
|
|
|
|
total_due = len(list_of_due_cards_by_ids(user_id)) - total_new
|
|
|
|
rated_today_new = rated_today_by_staus("new", user_id)
|
|
|
|
rated_today_due = rated_today_by_staus("due", user_id)
|
|
|
|
remaining_new_today = remaining_items(max_new, total_new, rated_today_new)
|
|
|
|
remaining_due_today = remaining_items(max_due, total_due, rated_today_due)
|
2022-06-15 02:06:59 +02:00
|
|
|
|
2022-06-05 18:56:40 +02:00
|
|
|
if request.method == "POST":
|
2022-06-04 21:58:05 +02:00
|
|
|
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":
|
2022-06-14 02:26:38 +02:00
|
|
|
#preverimo če so sploh karte v collectionu
|
2022-06-14 14:47:12 +02:00
|
|
|
print("userID", user_id)
|
2022-06-14 02:26:38 +02:00
|
|
|
c = dbsession.query(Card).filter(Card.owner_id == user_id).all()
|
|
|
|
if c == []:
|
|
|
|
print("ne najdem collectiona")
|
2022-06-14 14:47:12 +02:00
|
|
|
return render_template("error/no_cards_in_collection.html", username=username)
|
2022-06-26 18:30:11 +02:00
|
|
|
|
2022-08-16 10:50:03 +02:00
|
|
|
return redirect(url_for("deck"))
|
2022-06-04 21:58:05 +02:00
|
|
|
elif action == "matches":
|
2022-06-14 02:26:38 +02:00
|
|
|
return redirect(url_for("matches.index"))
|
2022-06-04 21:58:05 +02:00
|
|
|
elif action == "upload":
|
2022-06-05 18:56:40 +02:00
|
|
|
return redirect(url_for("upload.index"))
|
2022-06-04 21:58:05 +02:00
|
|
|
elif action == "settings":
|
2022-06-23 16:01:16 +02:00
|
|
|
settings = get_settings(user_id)
|
|
|
|
return render_template("settings.html", username=username, user_id=user_id, settings=settings)
|
2022-06-04 21:58:05 +02:00
|
|
|
elif action == "instructions":
|
2022-06-23 14:39:16 +02:00
|
|
|
return render_template("instructions.html", username=username, user_id=user_id)
|
2022-06-04 21:58:05 +02:00
|
|
|
|
2022-10-31 17:40:25 +01:00
|
|
|
return render_template("menu.html", username=username, deck_status=status, remaining_due=remaining_due_today, remaining_new=remaining_new_today)
|