try to catch edgecase bugs...
parent
edf0dd1ffa
commit
36caf80a34
32
menu.py
32
menu.py
|
@ -5,9 +5,10 @@ from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
from config import CONFIG
|
from config import CONFIG
|
||||||
from create_db import Deck
|
from create_db import Deck, Card
|
||||||
|
|
||||||
from deck import get_deck, probabilistic_deck_generator
|
from deck import get_deck, probabilistic_deck_generator
|
||||||
|
from auth import login
|
||||||
|
|
||||||
bp = Blueprint('menu', __name__, url_prefix='/menu')
|
bp = Blueprint('menu', __name__, url_prefix='/menu')
|
||||||
|
|
||||||
|
@ -17,6 +18,9 @@ dbsession = dbsessionmaker()
|
||||||
|
|
||||||
@bp.route("/", methods=("GET", "POST"))
|
@bp.route("/", methods=("GET", "POST"))
|
||||||
def index():
|
def index():
|
||||||
|
if 'user_id' not in session:
|
||||||
|
return login()
|
||||||
|
|
||||||
if 'user_id' in session:
|
if 'user_id' in session:
|
||||||
user_id = session['user_id']
|
user_id = session['user_id']
|
||||||
username = session['username']
|
username = session['username']
|
||||||
|
@ -29,19 +33,29 @@ def index():
|
||||||
if action == "new_session":
|
if action == "new_session":
|
||||||
# @TODO tu bi moral preveriti če je kak unfinished deck, potem bi pisalo continiue, namesto new
|
# @TODO tu bi moral preveriti če je kak unfinished deck, potem bi pisalo continiue, namesto new
|
||||||
|
|
||||||
|
#preverimo če so sploh karte v collectionu
|
||||||
|
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")
|
||||||
|
|
||||||
#ustvari novi vnos v Deck
|
#ustvari novi vnos v Deck
|
||||||
deck = probabilistic_deck_generator(user_id, 5, 5)
|
deck = probabilistic_deck_generator(user_id, 5, 5)
|
||||||
cards_by_id = get_deck(deck)
|
cards_by_id = get_deck(deck)
|
||||||
number_of_cards = len(cards_by_id.split(","))
|
if cards_by_id == None:
|
||||||
|
print("DECK IS NONE")
|
||||||
print(cards_by_id, number_of_cards)
|
return render_template(index())
|
||||||
deck = Deck(cards_by_id=cards_by_id, owner_id=user_id, number_of_cards=number_of_cards, current_card=0, completed=False)
|
else:
|
||||||
dbsession.add(deck)
|
number_of_cards = len(cards_by_id.split(","))
|
||||||
dbsession.commit()
|
|
||||||
|
print(cards_by_id, number_of_cards)
|
||||||
|
deck = Deck(cards_by_id=cards_by_id, owner_id=user_id, number_of_cards=number_of_cards, current_card=0, completed=False)
|
||||||
|
dbsession.add(deck)
|
||||||
|
dbsession.commit()
|
||||||
|
|
||||||
return redirect(url_for("deck"))
|
return redirect(url_for("deck"))
|
||||||
elif action == "matches":
|
elif action == "matches":
|
||||||
pass
|
return redirect(url_for("matches.index"))
|
||||||
elif action == "upload":
|
elif action == "upload":
|
||||||
return redirect(url_for("upload.index"))
|
return redirect(url_for("upload.index"))
|
||||||
elif action == "settings":
|
elif action == "settings":
|
||||||
|
|
Loading…
Reference in New Issue