Browse Source

cleanup

master
Kostanjevec 2 months ago
parent
commit
dac7fe61a0
  1. 19
      menu.py

19
menu.py

@ -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)
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 == "":
flash("Error: Attempted to make deck with 0 cards. Maybe check settings :)")
return render_template("menu/menu.html")
if cards_by_id == "":
return render_template("error/no_cards_in_collection.html", username=username)
else:
number_of_cards = len(cards_by_id.split(","))
@ -76,4 +75,4 @@ def index():
return render_template("about.html", username=username, user_id=user_id)
return render_template("menu/menu.html", username=username, deck_status=deck_status)
return render_template("menu/menu.html", username=username, deck_status=deck_status)
Loading…
Cancel
Save