Creating dynamic graph based on user input

Viewed 168

We have recieved a task in which we have to create some dynamic graph based on the user's choice from the form. It doesn't have to be or look professional, it can be just 4 css squares which are moving up based on the choice from the form. The technology we can use is Python, HTML & CSS.

from flask import Flask, redirect, render_template
from flask_wtf import FlaskForm
from wtforms import RadioField
import sqlite3

app = Flask(__name__)
app.debug = True
app.secret_key = "ngwihlgnijgbijagrneijzugdtr"


class AnketaForm(FlaskForm):
    volba = RadioField(choices=[("volba1", "perfect"),
                                ("volba2", "passing through"),
                                ("volba3", "bad"),
                                ("volba4", "i dont mind")])


@app.route("/", methods=["GET", "POST"])
def anketa():
    form = AnketaForm()
    hlas = form.volba.data
    if form.validate_on_submit():
        con = sqlite3.connect("anketa.db")
        cur = con.cursor()
        cur.execute(f"INSERT INTO anketa({hlas}) VALUES(1)")
        con.commit()
        con.close()
        return redirect("/vysledky")
    return render_template("anketa.html", form=form)


@app.route("/vysledky")
def vysledky():
    con = sqlite3.connect("anketa.db")
    cur = con.cursor()
    cur.execute(
        "SELECT SUM (volba1), SUM(volba2), SUM(volba3), SUM(volba4) FROM anketa")
    vysledky = cur.fetchone()
    con.close()

    return render_template("vysledky.html", vysledky=vysledky)


if __name__ == "__main__":
    app.run()
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Anketa</h1>
    <form method="POST">
        {{form.hidden_tag()}}
        {{form.volba}}
        <input type="submit" value="vote">
    </form>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Anketa</title>
</head>
<body>
    <h1>Thank you for your vote!</h1>
    <div></div>
    <div></div>
    <div>{{vysledky[0]}}</div>
    <a href="/">Back</a>
   
</body>
</html>

I've tried almost everything, but nothing even didn't lead me to some solution.

0 Answers
Related