master
Kostanjevec 2022-06-26 18:30:11 +02:00
parent a9de33dfb8
commit dac7fe61a0
1 changed files with 10 additions and 11 deletions

19
menu.py
View File

@ -2,9 +2,7 @@ from flask import (
Blueprint, flash, redirect, render_template, request, session, url_for
)
from config import CONFIG
from create_db import Deck, Card, get_session
from deck import get_deck, probabilistic_deck_generator
from settings import get_settings
from auth import login
@ -31,7 +29,6 @@ def index():
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":
# @TODO tu bi moral preveriti če je kak unfinished deck, potem bi pisalo continiue, namesto new
old_deck = dbsession.query(Deck).filter(Deck.completed == 0, Deck.owner_id == user_id).all()
if old_deck != []:
return redirect(url_for("deck"))
@ -39,20 +36,22 @@ def index():
#preverimo če so sploh karte v collectionu
print("userID", user_id)
c = dbsession.query(Card).filter(Card.owner_id == user_id).all()
#print(dbsession.query(Card).all())
#print(c)
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)
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 == "":
flash("Error: Attempted to make deck with 0 cards. Maybe check settings :)")
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/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(","))