48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
from flask import (
|
|
Blueprint, flash, redirect, render_template, request, session, url_for
|
|
)
|
|
from create_db import Card, get_session
|
|
from sr_session import remaining_by_status, schedule_status
|
|
from settings import get_settings
|
|
from auth import login
|
|
|
|
bp = Blueprint('menu', __name__, url_prefix='/menu')
|
|
|
|
@bp.route("/", methods=("GET", "POST"))
|
|
def index():
|
|
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)
|
|
status = schedule_status(user_id)
|
|
remaining_new = remaining_by_status(user_id, "new")
|
|
remaining_due = remaining_by_status(user_id, "due")-remaining_new
|
|
|
|
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":
|
|
#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)
|
|
|
|
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)
|
|
|
|
return render_template("menu.html", username=username, deck_status=status, remaining_due=remaining_due, remaining_new=remaining_new)
|