contentmatcher/menu.py

55 lines
1.9 KiB
Python
Raw Normal View History

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 sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config import CONFIG
2022-06-13 12:35:10 +02:00
from create_db import Deck
from deck import get_deck, probabilistic_deck_generator
2022-06-04 21:58:05 +02:00
bp = Blueprint('menu', __name__, url_prefix='/menu')
engine = create_engine(CONFIG['DB_CONNECTION'])
dbsessionmaker = sessionmaker(bind=engine)
dbsession = dbsessionmaker()
@bp.route("/", methods=("GET", "POST"))
def index():
if 'user_id' in session:
user_id = session['user_id']
username = session['username']
print(username)
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":
# @TODO tu bi moral preveriti če je kak unfinished deck, potem bi pisalo continiue, namesto new
#ustvari novi vnos v Deck
deck = probabilistic_deck_generator(user_id, 5, 5)
cards_by_id = get_deck(deck)
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-04 21:58:05 +02:00
return redirect(url_for("deck"))
elif action == "matches":
pass
elif action == "upload":
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-13 14:23:37 +02:00
return render_template("menu/menu.html", username=username)