From bad50c51cf2f5174c83b66c1a5531faea8324a07 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sun, 13 Nov 2022 21:37:54 +0100 Subject: [PATCH] Display all votes --- app.py | 36 ++++++++++- static/style.css | 22 ++++++- templates/date_result_ballots.html | 33 ++++++++++ templates/place_result_ballots.html | 33 ++++++++++ templates/time_result_ballots.html | 33 ++++++++++ templates/vote.html | 93 +++++++++++++++-------------- 6 files changed, 202 insertions(+), 48 deletions(-) create mode 100644 templates/date_result_ballots.html create mode 100644 templates/place_result_ballots.html create mode 100644 templates/time_result_ballots.html diff --git a/app.py b/app.py index de0b93c..6129b90 100644 --- a/app.py +++ b/app.py @@ -280,6 +280,34 @@ def result_place(meet_id): return render_template("place_result_fragment.html", result=result) +@app.get("/result//date/ballot") +def result_ballots_date(meet_id): + ballots = get_ballots(meet_id, "date") + result = instantrunoff_forward(meet_id, "date") + + return render_template( + "date_result_ballots.html", + result=result, ballots=ballots) + +@app.get("/result//time/ballot") +def result_ballots_time(meet_id): + ballots = get_ballots(meet_id, "time") + result = instantrunoff_forward(meet_id, "time") + + return render_template( + "time_result_ballots.html", + result=result, ballots=ballots) + +@app.get("/result//place/ballot") +def result_ballots_place(meet_id): + ballots = get_ballots(meet_id, "place") + result = instantrunoff_forward(meet_id, "place") + + return render_template( + "place_result_ballots.html", + result=result, ballots=ballots) + + def send_mail(email_address, confirmation_url): msg = email.message.EmailMessage() msg["From"] ="noreply@hjp.at" @@ -294,8 +322,10 @@ def get_ballots(meet_id, kind): csr = get_cursor() q = f""" - select {kind}.*, bod, position - from {kind} join {kind}_vote on {kind}.id = {kind}_vote.{kind} + select {kind}.*, bod, position, email + from {kind} + join {kind}_vote on {kind}.id = {kind}_vote.{kind} + join bod on bod = bod.id where meet = %s order by bod, position """ @@ -361,7 +391,7 @@ def get_cursor(): def get_db(): if "db" not in g: - g.db = psycopg.connect(dbname=config.dbname) + g.db = psycopg.connect(dbname=config.dbname, user=config.dbuser) return g.db @app.teardown_appcontext diff --git a/static/style.css b/static/style.css index eb95f88..4300486 100644 --- a/static/style.css +++ b/static/style.css @@ -18,7 +18,7 @@ body { cursor: grabbing; } -body { +.voteform { padding: 1rem; display: grid; grid-template-columns: 1fr 1fr; @@ -45,3 +45,23 @@ h1, h2 { color: #888; } +.ballot { + border: 1px solid black; + margin: 1em; + border-radius: 0.4em; +} + +.pos_1 { + background-color: hsl(120, 80%, 70%); + color: black; +} + +.ballotlist { + display: flex; + flex-wrap: wrap; +} + +.voter { + padding: 1em; + background-color: hsl(240, 10%, 80%); +} diff --git a/templates/date_result_ballots.html b/templates/date_result_ballots.html new file mode 100644 index 0000000..227eed0 --- /dev/null +++ b/templates/date_result_ballots.html @@ -0,0 +1,33 @@ + + + + + + + + + + +
+ {% for ballot in ballots %} +
+
+ {{ballot.0.email}} +
+ {% for vote in ballot %} +
+ {{ vote.display or vote.date }} +
+ {% endfor %} +
+ {% endfor %} +
+ + diff --git a/templates/place_result_ballots.html b/templates/place_result_ballots.html new file mode 100644 index 0000000..faf7cd7 --- /dev/null +++ b/templates/place_result_ballots.html @@ -0,0 +1,33 @@ + + + + + + + + + + +
+ {% for ballot in ballots %} +
+
+ {{ballot.0.email}} +
+ {% for vote in ballot %} +
+ {{ vote.name }} +
+ {% endfor %} +
+ {% endfor %} +
+ + diff --git a/templates/time_result_ballots.html b/templates/time_result_ballots.html new file mode 100644 index 0000000..4fbebf8 --- /dev/null +++ b/templates/time_result_ballots.html @@ -0,0 +1,33 @@ + + + + + + + + + + +
+ {% for ballot in ballots %} +
+
+ {{ballot.0.email}} +
+ {% for vote in ballot %} +
+ {{ vote.display or vote.time }} +
+ {% endfor %} +
+ {% endfor %} +
+ + diff --git a/templates/vote.html b/templates/vote.html index e7e6caf..cac771f 100644 --- a/templates/vote.html +++ b/templates/vote.html @@ -8,54 +8,59 @@ -

Hallo, {{ session.user.email }}!

-

- Bisher haben abgestimmt: - {% for voter in voters %} - {{ voter.email }}{% if not loop.last %},{% endif %} +

+

Hallo, {{ session.user.email }}!

+

+ Bisher haben abgestimmt: + {% for voter in voters %} + {{ voter.email }}{% if not loop.last %},{% endif %} + {% endfor %} +

+

+ {{ meet.title }} +

+

+ An welchem Tag? + [details] +

+
+ {% for d in dates %} +
+ {{ d.display or d.date }} + +
{% endfor %} -

-

- {{ meet.title }} -

-

- An welchem Tag? -

- - {% for d in dates %} -
- {{ d.display or d.date }} - + +
- {% endfor %} - -
-
-

- Zu welcher Zeit? -

-
- {% for d in times %} -
- {{ d.display or d.time }} - +

+ Zu welcher Zeit? + [details] +

+ + {% for d in times %} +
+ {{ d.display or d.time }} + +
+ {% endfor %} + +
- {% endfor %} - -
-
-

- An welchem Ort? -

-
- {% for d in places %} -
- {{ d.name }} - +

+ An welchem Ort? + [details] +

+ + {% for d in places %} +
+ {{ d.name }} + +
+ {% endfor %} + +
- {% endfor %} - -