contentmatcher/menu.py

48 lines
2.0 KiB
Python
Raw Normal View History

2022-06-04 21:58:05 +02:00
from flask import (
2022-06-23 22:23:39 +02:00
Blueprint, flash, redirect, render_template, request, session, url_for
2022-06-04 21:58:05 +02:00
)
from create_db import Card, get_session
from sr_session import remaining_by_status, schedule_status
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)
status = schedule_status(user_id)
remaining_new = remaining_by_status(user_id, "new")
remaining_due = remaining_by_status(user_id, "due")-remaining_new
2022-06-15 02:06:59 +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
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":
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":
return render_template("instructions.html", username=username, user_id=user_id)
2022-06-04 21:58:05 +02:00
return render_template("menu.html", username=username, deck_status=status, remaining_due=remaining_due, remaining_new=remaining_new)