Compare commits
7 Commits
63f07e9b9f
...
e2da724551
Author | SHA1 | Date |
---|---|---|
Kostanjevec | e2da724551 | |
Kostanjevec | 36caf80a34 | |
Kostanjevec | edf0dd1ffa | |
Kostanjevec | effd1f915f | |
Kostanjevec | b787449905 | |
Kostanjevec | fb67c7a49f | |
Kostanjevec | 17a15dd416 |
18
app.py
18
app.py
|
@ -9,6 +9,7 @@ from deck import bp as deck_bp
|
|||
from menu import bp as menu_bp
|
||||
from upload import bp as upload_bp
|
||||
from share import share
|
||||
from matches import bp as matches_bp
|
||||
|
||||
from create_db import Card, Deck
|
||||
from config import CONFIG
|
||||
|
@ -57,6 +58,10 @@ def create_app(test_config=None):
|
|||
deck_query = dbsession.query(Deck).filter(Deck.owner_id == user_id)
|
||||
deck_object = deck_query.filter(Deck.completed == False).first()
|
||||
# @TODO: ce deck, ne obstaja, kaj naj zaj jas?
|
||||
if len(deck_object.cards_by_id.split(",")) == 0:
|
||||
deck_query.filter(Deck)
|
||||
return index()
|
||||
|
||||
|
||||
deck_id = deck_object.id
|
||||
|
||||
|
@ -116,18 +121,16 @@ def create_app(test_config=None):
|
|||
show_card = dbsession.query(Card).get(show_card_id)
|
||||
|
||||
if not show_card:
|
||||
raise Exception("Ne najdem naslednje karte")
|
||||
print("SHOWWWWWWW")
|
||||
return render_template("error/no_cards_in_collection.html")
|
||||
#raise Exception("Ne najdem naslednje karte")
|
||||
|
||||
# Prikaži obrazec
|
||||
return render_template("deck/index.html", username=username, card=show_card)
|
||||
|
||||
|
||||
@app.route("/share_button", methods=["GET", "POST"])
|
||||
def share_button():
|
||||
userid = session["user_id"]
|
||||
username = session["username"]
|
||||
card_number = session["card_number"]
|
||||
|
||||
def share_button():
|
||||
print("share!!!")
|
||||
return redirect(url_for("deck"))
|
||||
|
||||
|
@ -141,12 +144,13 @@ def create_app(test_config=None):
|
|||
def match():
|
||||
return "match"
|
||||
|
||||
|
||||
|
||||
#app.register_blueprint(bp) # ??
|
||||
app.register_blueprint(auth_bp)
|
||||
app.register_blueprint(deck_bp)
|
||||
app.register_blueprint(menu_bp)
|
||||
app.register_blueprint(upload_bp)
|
||||
app.register_blueprint(matches_bp)
|
||||
app.add_url_rule('/', endpoint='index')
|
||||
|
||||
return app
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
from flask import (
|
||||
Blueprint, redirect, render_template, request, session, url_for
|
||||
)
|
||||
from requests import get
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from config import CONFIG
|
||||
|
||||
from create_db import Card
|
||||
|
||||
bp = Blueprint('matches', __name__, url_prefix='/matches')
|
||||
|
||||
|
||||
engine = create_engine(CONFIG['DB_CONNECTION'])
|
||||
dbsessionmaker = sessionmaker(bind=engine)
|
||||
dbsession = dbsessionmaker()
|
||||
|
||||
|
||||
def get_matches(user_id):
|
||||
list_of_matches = []
|
||||
|
||||
#in all shared cards for the ones you votes yes
|
||||
all_cards = dbsession.query(Card)
|
||||
all_shared_of_user_of_ir_1 = all_cards.filter(Card.share_id != "0", Card.owner_id == user_id, Card.interest_rate == 1).all()
|
||||
if all_shared_of_user_of_ir_1 == []:
|
||||
return list_of_matches
|
||||
|
||||
# see who else voted yes
|
||||
for c in all_shared_of_user_of_ir_1:
|
||||
others_yes = all_cards.filter(Card.share_id == c.share_id, Card.interest_rate == 1).all()
|
||||
if others_yes == []:
|
||||
pass
|
||||
else:
|
||||
list_of_matches.append(others_yes)
|
||||
|
||||
return list_of_matches
|
||||
|
||||
@bp.route("/", methods=("GET", "POST"))
|
||||
def index():
|
||||
if not 'user_id' in session:
|
||||
redirect(url_for('index'))
|
||||
user_id = session["user_id"]
|
||||
username = session["username"]
|
||||
|
||||
list_of_matches = get_matches(user_id)
|
||||
|
||||
#@TODO tu bi morali dodati še nek users object, da own_id pretvorimo v username
|
||||
return render_template("matches.html", username=username, list_of_matches=list_of_matches)
|
32
menu.py
32
menu.py
|
@ -5,9 +5,10 @@ from sqlalchemy import create_engine
|
|||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from config import CONFIG
|
||||
from create_db import Deck
|
||||
from create_db import Deck, Card
|
||||
|
||||
from deck import get_deck, probabilistic_deck_generator
|
||||
from auth import login
|
||||
|
||||
bp = Blueprint('menu', __name__, url_prefix='/menu')
|
||||
|
||||
|
@ -17,6 +18,9 @@ dbsession = dbsessionmaker()
|
|||
|
||||
@bp.route("/", methods=("GET", "POST"))
|
||||
def index():
|
||||
if 'user_id' not in session:
|
||||
return login()
|
||||
|
||||
if 'user_id' in session:
|
||||
user_id = session['user_id']
|
||||
username = session['username']
|
||||
|
@ -29,19 +33,29 @@ def index():
|
|||
if action == "new_session":
|
||||
# @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
|
||||
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()
|
||||
if cards_by_id == None:
|
||||
print("DECK IS NONE")
|
||||
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()
|
||||
|
||||
return redirect(url_for("deck"))
|
||||
return redirect(url_for("deck"))
|
||||
elif action == "matches":
|
||||
pass
|
||||
return redirect(url_for("matches.index"))
|
||||
elif action == "upload":
|
||||
return redirect(url_for("upload.index"))
|
||||
elif action == "settings":
|
||||
|
|
14
share.py
14
share.py
|
@ -12,17 +12,17 @@ dbsession = dbsessionmaker()
|
|||
|
||||
|
||||
def share(card, user_id):
|
||||
print(card.share_id, card.id)
|
||||
#tu bi lahko naredili nek autoincrement ampak i guess da hash unique idja tudi daje unique share_id, tega potem uporabljamo, da preverimo matche
|
||||
h = md5(str(card.id).encode("utf-8")).hexdigest()
|
||||
print("hash: ", h)
|
||||
card.share_id = h
|
||||
|
||||
# all users
|
||||
users = dbsession.query(User).filter(User.id != user_id).all()
|
||||
for user in users:
|
||||
print("hey, ", user.id)
|
||||
#TODO skip če že ima ta card v db.
|
||||
new_card = card = Card(title=card.title, interest_rate=-1.0, owner_id=user.id, item_location=card.item_location, last_review=None, share_id=h)
|
||||
dbsession.add(new_card)
|
||||
dbsession.commit()
|
||||
#skip če že ima ta card v db.
|
||||
existing = dbsession.query(Card).filter(Card.title == card.title, Card.owner_id==user.id).all()
|
||||
if existing == []:
|
||||
print("sharing to, ", user.id)
|
||||
new_card = card = Card(title=card.title, interest_rate=-1.0, owner_id=user.id, item_location=card.item_location, last_review=None, share_id=h)
|
||||
dbsession.add(new_card)
|
||||
dbsession.commit()
|
|
@ -0,0 +1,6 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Error: No cards foud</h1>
|
||||
<p>No cards were found in your collection. Consider <a href="{{ url_for('upload.index') }}">uploading</a> some.</p>
|
||||
{% endblock %}
|
|
@ -0,0 +1,19 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block header %}
|
||||
<head>Matches</head>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>Hello</p>
|
||||
|
||||
{% if list_of_matches %}
|
||||
{% for match in list_of_matches %}
|
||||
{% for card in match %}
|
||||
<p>{{ card['title'] }}</p>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p>You have no matches at the moment</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -45,8 +45,8 @@ def upload_file():
|
|||
script_path = os.path.dirname(os.path.abspath(__file__))
|
||||
temp_path = os.path.join(script_path, "temp")
|
||||
|
||||
|
||||
#a lot of stuff can wrong here and nobody may know
|
||||
# @TODO ne dela za več fajlov
|
||||
# a lot of stuff can wrong here and nobody may know
|
||||
with tempfile.NamedTemporaryFile(dir=temp_path, delete=False) as fp:
|
||||
fp.write(upload.stream.read())
|
||||
path = fp.name
|
||||
|
|
Loading…
Reference in New Issue