Show voters and order

This commit is contained in:
Peter J. Holzer 2022-12-08 14:12:52 +01:00
parent c45e514bfc
commit 537c2ba4b5
8 changed files with 146 additions and 42 deletions

99
app.py
View File

@ -175,14 +175,43 @@ def vote_date():
result = instantrunoff_forward(meet_id, "date")
log.debug("result = %s", result)
return render_template("date_vote_fragment.html", dates=dates, result=result)
csr.execute(
"""
select distinct email, short
from date_vote
join date on date_vote.date = date.id
join bod on date_vote.bod = bod.id
where meet = %s
order by email
""",
(meet_id,))
voters = csr.fetchall()
return render_template(
"date_vote_fragment.html",
dates=dates, result=result, voters=voters)
@app.get("/result/<int:meet_id>/date")
def result_date(meet_id):
result = instantrunoff_forward(meet_id, "date")
log.debug("result = %s", result)
return render_template("date_result_fragment.html", result=result)
csr = get_cursor()
csr.execute(
"""
select distinct email, short
from date_vote
join date on date_vote.date = date.id
join bod on date_vote.bod = bod.id
where meet = %s
order by email
""",
(meet_id,))
voters = csr.fetchall()
return render_template(
"date_result_fragment.html",
result=result, voters=voters)
@ -224,14 +253,43 @@ def vote_time():
result = instantrunoff_forward(meet_id, "time")
log.debug("result = %s", result)
return render_template("time_vote_fragment.html", times=times, result=result)
csr.execute(
"""
select distinct email, short
from time_vote
join time on time_vote.time = time.id
join bod on time_vote.bod = bod.id
where meet = %s
order by email
""",
(meet_id,))
voters = csr.fetchall()
return render_template(
"time_vote_fragment.html",
times=times, result=result, voters=voters)
@app.get("/result/<int:meet_id>/time")
def result_time(meet_id):
result = instantrunoff_forward(meet_id, "time")
log.debug("result = %s", result)
return render_template("time_result_fragment.html", result=result)
csr = get_cursor()
csr.execute(
"""
select distinct email, short
from time_vote
join time on time_vote.time = time.id
join bod on time_vote.bod = bod.id
where meet = %s
order by email
""",
(meet_id,))
voters = csr.fetchall()
return render_template(
"time_result_fragment.html",
result=result, voters=voters)
@app.post("/vote/place")
def vote_place():
@ -271,7 +329,21 @@ def vote_place():
result = instantrunoff_forward(meet_id, "place")
log.debug("result = %s", result)
return render_template("place_vote_fragment.html", places=places, result=result)
csr.execute(
"""
select distinct email, short
from place_vote
join place on place_vote.place = place.id
join bod on place_vote.bod = bod.id
where meet = %s
order by email
""",
(meet_id,))
voters = csr.fetchall()
return render_template(
"place_vote_fragment.html",
places=places, result=result, voters=voters)
@app.get("/result/<int:meet_id>/place")
@ -279,7 +351,22 @@ def result_place(meet_id):
result = instantrunoff_forward(meet_id, "place")
log.debug("result = %s", result)
return render_template("place_result_fragment.html", result=result)
csr = get_cursor()
csr.execute(
"""
select distinct email, short
from place_vote
join place on place_vote.place = place.id
join bod on place_vote.bod = bod.id
where meet = %s
order by email
""",
(meet_id,))
voters = csr.fetchall()
return render_template(
"place_result_fragment.html",
result=result, voters=voters)
@app.get("/result/<int:meet_id>/date/ballot")

View File

@ -1,7 +1,8 @@
<div id="r-day" hx-swap-oob="true">
Ergebnis ({% for v in voters %}{{ v.short or v.email }}{% if not loop.last %}, {% endif %}{% endfor %}):
{% for r in result %}
<div class="result-item">
{{ r.display or r.date }}
{{ loop.index }}. {{ r.display or r.date }}
</div>
{% endfor %}
</div>

View File

@ -1,13 +1,14 @@
{% for d in dates %}
<div class="sort-item">
{{ d.display or d.date }}
{{ loop.index }}. {{ d.display or d.date }}
<input type="hidden" name="date" value="{{d.id}}">
</div>
{% endfor %}
<div id="r-day" hx-swap-oob="true">
Ergebnis ({% for v in voters %}{{ v.short or v.email }}{% if not loop.last %}, {% endif %}{% endfor %}):
{% for r in result %}
<div class="result-item">
{{ r.display or r.date }}
{{ loop.index }}. {{ r.display or r.date }}
</div>
{% endfor %}
</div>

View File

@ -1,7 +1,8 @@
<div id="r-place" hx-swap-oob="true">
Ergebnis ({% for v in voters %}{{ v.short or v.email }}{% if not loop.last %}, {% endif %}{% endfor %}):
{% for r in result %}
<div class="result-item">
{{ r.name }}
{{ loop.index }}. {{ r.name }}
</div>
{% endfor %}
</div>

View File

@ -1,13 +1,14 @@
{% for d in places %}
<div class="sort-item">
{{ d.name }}
{{ loop.index }}. {{ d.name }}
<input type="hidden" name="place" value="{{d.id}}">
</div>
{% endfor %}
<div id="r-place" hx-swap-oob="true">
Ergebnis ({% for v in voters %}{{ v.short or v.email }}{% if not loop.last %}, {% endif %}{% endfor %}):
{% for r in result %}
<div class="result-item">
{{ r.name }}
{{ loop.index }}. {{ r.name }}
</div>
{% endfor %}
</div>

View File

@ -1,7 +1,8 @@
<div id="r-time" hx-swap-oob="true">
Ergebnis ({% for v in voters %}{{ v.short or v.email }}{% if not loop.last %}, {% endif %}{% endfor %}):
{% for r in result %}
<div class="result-item">
{{ r.display or r.time }}
{{ loop.index }}. {{ r.display or r.time }}
</div>
{% endfor %}
</div>

View File

@ -1,13 +1,14 @@
{% for d in times %}
<div class="sort-item">
{{ d.display or d.time }}
{{ loop.index }}. {{ d.display or d.time }}
<input type="hidden" name="time" value="{{d.id}}">
</div>
{% endfor %}
<div id="r-time" hx-swap-oob="true">
Ergebnis ({% for v in voters %}{{ v.short or v.email }}{% if not loop.last %}, {% endif %}{% endfor %}):
{% for r in result %}
<div class="result-item">
{{ r.display or r.time }}
{{ loop.index }}. {{ r.display or r.time }}
</div>
{% endfor %}
</div>

View File

@ -8,6 +8,11 @@
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<header>
<img src="/static/meat.svg" class="logo logo-1">
<img src="/static/meet.svg" class="logo logo-2">
<h1> {{ meet.title }} </h1>
</header>
<div class="voteform">
<p id="hello">Hallo, {{ session.user.email }}!</p>
<p id="voters">
@ -16,49 +21,55 @@
{{ voter.email }}{% if not loop.last %},{% endif %}
{% endfor %}
</p>
<h1>
{{ meet.title }}
</h1>
<h2 id="h-day">
An welchem Tag?
<a href="/result/{{meet.id}}/date/ballot">[details]</a>
</h2>
<form id="v-day" class="sortable" hx-post="/vote/date" hx-trigger="end">
{% for d in dates %}
<div class="sort-item">
{{ d.display or d.date }}
<input type="hidden" name="date" value="{{d.id}}">
</div>
{% endfor %}
</form>
<div>
Ordne die Optionen nach Präferenz:
<form id="v-day" class="sortable" hx-post="/vote/date" hx-trigger="end">
{% for d in dates %}
<div class="sort-item">
{{ loop.index }}. {{ d.display or d.date }}
<input type="hidden" name="date" value="{{d.id}}">
</div>
{% endfor %}
</form>
</div>
<div id="r-day" hx-get="/result/{{meet.id}}/date" hx-trigger="load">
</div>
<h2 id="h-time">
Zu welcher Zeit?
<a href="/result/{{meet.id}}/time/ballot">[details]</a>
</h2>
<form id="v-time" class="sortable" hx-post="/vote/time" hx-trigger="end">
{% for d in times %}
<div class="sort-item">
{{ d.display or d.time }}
<input type="hidden" name="time" value="{{d.id}}">
</div>
{% endfor %}
</form>
<div>
Ordne die Optionen nach Präferenz:
<form id="v-time" class="sortable" hx-post="/vote/time" hx-trigger="end">
{% for d in times %}
<div class="sort-item">
{{ loop.index }}. {{ d.display or d.time }}
<input type="hidden" name="time" value="{{d.id}}">
</div>
{% endfor %}
</form>
</div>
<div id="r-time" hx-get="/result/{{meet.id}}/time" hx-trigger="load">
</div>
<h2 id="h-place">
An welchem Ort?
<a href="/result/{{meet.id}}/place/ballot">[details]</a>
</h2>
<form id="v-place" class="sortable" hx-post="/vote/place" hx-trigger="end">
{% for d in places %}
<div class="sort-item">
{{ d.name }}
<input type="hidden" name="place" value="{{d.id}}">
</div>
{% endfor %}
</form>
<div>
Ordne die Optionen nach Präferenz:
<form id="v-place" class="sortable" hx-post="/vote/place" hx-trigger="end">
{% for d in places %}
<div class="sort-item">
{{ loop.index }}. {{ d.name }}
<input type="hidden" name="place" value="{{d.id}}">
</div>
{% endfor %}
</form>
</div>
<div id="r-place" hx-get="/result/{{meet.id}}/place" hx-trigger="load">
</div>
</div>