post from buttons to db
parent
7417222ee9
commit
d06413a5fc
43
app.py
43
app.py
|
@ -1,9 +1,20 @@
|
|||
from collections import UserList
|
||||
import os
|
||||
|
||||
from sqlalchemy import case
|
||||
|
||||
from auth import login_required, bp as auth_bp
|
||||
from deck import deck, bp as deck_bp
|
||||
from flask import Flask, render_template, session
|
||||
from deck import get_deck, bp as deck_bp
|
||||
from flask import Flask, render_template, session, request
|
||||
|
||||
from create_db import Card
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from config import CONFIG
|
||||
|
||||
engine = create_engine(CONFIG['DB_CONNECTION'])
|
||||
dbsessionmaker = sessionmaker(bind=engine)
|
||||
dbsession = dbsessionmaker()
|
||||
|
||||
|
||||
def create_app(test_config=None):
|
||||
|
@ -27,23 +38,43 @@ def create_app(test_config=None):
|
|||
except OSError:
|
||||
pass
|
||||
|
||||
# a simple page that says hello
|
||||
|
||||
@app.route('/')
|
||||
@login_required
|
||||
def index():
|
||||
return 'redirecting' # meče skoz nazaj na login TODO
|
||||
|
||||
@app.route('/deck', methods=["GET", "POST"])
|
||||
#@login_required
|
||||
@app.route('/deck/index', methods=("GET", "POST"))
|
||||
def deck():
|
||||
if 'user_id' in session:
|
||||
user_id = session['user_id']
|
||||
username = session['username']
|
||||
return render_template("deck/index.html", username=username)
|
||||
d = get_deck(user_id)
|
||||
|
||||
for card in d: #TODO to ne dela, nevem kako renderat zapooredno kartic
|
||||
if request.method == 'POST':
|
||||
rate = request.form['rate']
|
||||
cardtitle = request
|
||||
print(rate)
|
||||
if rate == "Yes":
|
||||
k = 1
|
||||
elif rate == "Maybe":
|
||||
k = 0.5
|
||||
elif rate == "No":
|
||||
k = 0.1
|
||||
|
||||
|
||||
print(card.id)
|
||||
print(user_id)
|
||||
dbsession.query(Card).filter(Card.id == card.id).update({'interest_rate': abs(card.interest_rate*k)}) #TODO 1 mora nastavit na 1
|
||||
dbsession.commit()
|
||||
render_template("deck/index.html", username=username, card = card)
|
||||
return render_template("deck/index.html", username=username, card = card) # no idea kaj se tu dogaja...
|
||||
else:
|
||||
return index()
|
||||
|
||||
|
||||
|
||||
@app.route('/logout')
|
||||
def logout():
|
||||
session.pop("user_id", None)
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<nav>
|
||||
<h1>contentmatcher</h1>
|
||||
<ul>
|
||||
{% if g.user %}
|
||||
<li><span>{{ g.user['username'] }}</span>
|
||||
{% if username %}
|
||||
<li><span>{{username}}</span>
|
||||
<li><a href="{{ url_for('auth.logout') }}">Log Out</a>
|
||||
{% else %}
|
||||
<li><a href="{{ url_for('auth.register') }}">Register</a>
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block header %}
|
||||
<h1>{% block title %}DECK{% endblock %}</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>BODY</p>
|
||||
|
||||
<article class="post">
|
||||
<header>
|
||||
<div>
|
||||
<h1>{{ card['title'] }}</h1>
|
||||
<form method="post">
|
||||
<button input type="submit" name="rate" data-cardtitle=card[title] value="Yes">Yes</button>
|
||||
<button input type="submit" name="rate" value="Maybe">Maybe</button>
|
||||
<button input type="submit" name="rate" value="No">No</button>
|
||||
</form>
|
||||
</div>
|
||||
</header>
|
||||
</article>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue