2022-06-04 21:58:05 +02:00
|
|
|
from flask import (
|
2022-06-13 12:35:10 +02:00
|
|
|
Blueprint, redirect, render_template, request, session, url_for
|
2022-06-04 21:58:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
from config import CONFIG
|
2022-06-14 14:47:12 +02:00
|
|
|
from create_db import Deck, Card, get_session
|
2022-06-05 18:56:40 +02:00
|
|
|
|
|
|
|
from deck import get_deck, probabilistic_deck_generator
|
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)
|
|
|
|
|
2022-06-05 18:56:40 +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-12 20:06:24 +02:00
|
|
|
# @TODO tu bi moral preveriti če je kak unfinished deck, potem bi pisalo continiue, namesto new
|
2022-06-05 18:56:40 +02:00
|
|
|
|
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()
|
2022-06-14 14:47:12 +02:00
|
|
|
#print(dbsession.query(Card).all())
|
|
|
|
#print(c)
|
2022-06-14 02:26:38 +02:00
|
|
|
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-14 02:26:38 +02:00
|
|
|
|
2022-06-05 18:56:40 +02:00
|
|
|
#ustvari novi vnos v Deck
|
|
|
|
deck = probabilistic_deck_generator(user_id, 5, 5)
|
|
|
|
cards_by_id = get_deck(deck)
|
2022-06-14 02:26:38 +02:00
|
|
|
if cards_by_id == None:
|
2022-06-14 02:31:35 +02:00
|
|
|
print("Deck is none")
|
2022-06-14 02:26:38 +02:00
|
|
|
return render_template(index())
|
|
|
|
else:
|
|
|
|
number_of_cards = len(cards_by_id.split(","))
|
|
|
|
|
|
|
|
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()
|
2022-06-14 14:03:29 +02:00
|
|
|
dbsession.close()
|
2022-06-05 18:56:40 +02:00
|
|
|
|
2022-06-14 02:26:38 +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":
|
2022-06-05 18:56:40 +02:00
|
|
|
return redirect(url_for("upload.index"))
|
2022-06-04 21:58:05 +02:00
|
|
|
elif action == "settings":
|
|
|
|
pass
|
|
|
|
elif action == "instructions":
|
|
|
|
pass
|
|
|
|
elif action == "about":
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-06-14 14:03:29 +02:00
|
|
|
return render_template("menu/menu.html", username=username)
|