From b78744990528dc6efecaed0a05a06ce94490d85a Mon Sep 17 00:00:00 2001 From: Kostanjevec Date: Tue, 14 Jun 2022 02:17:58 +0200 Subject: [PATCH] added some matching functionality --- matches.py | 49 ++++++++++++++++++++++++++++++++++++++++++ templates/matches.html | 19 ++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 matches.py create mode 100644 templates/matches.html diff --git a/matches.py b/matches.py new file mode 100644 index 0000000..7f137cf --- /dev/null +++ b/matches.py @@ -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) \ No newline at end of file diff --git a/templates/matches.html b/templates/matches.html new file mode 100644 index 0000000..ba4597c --- /dev/null +++ b/templates/matches.html @@ -0,0 +1,19 @@ +{% extends 'base.html' %} + +{% block header %} + Matches +{% endblock %} + +{% block content %} +

Hello

+ +{% if list_of_matches %} + {% for match in list_of_matches %} + {% for card in match %} +

{{ card['title'] }}

+ {% endfor %} + {% endfor %} +{% else %} +

You have no matches at the moment

+{% endif %} +{% endblock %} \ No newline at end of file