polls: changes in template, display results when user has voted

This commit is contained in:
Eldeberen 2021-02-21 21:15:54 +01:00
parent 5958605d2b
commit b23fc15b6e
Signed by untrusted user: Darks
GPG Key ID: 7515644268BE1433
3 changed files with 13 additions and 16 deletions

View File

@ -81,10 +81,6 @@ table.thread td.author {
table.thread td {
vertical-align: top;
}
table.thread td:nth-child(2) {
padding-top: 0;
padding-bottom: 0;
}
table.thread div.info {
float: right;

View File

@ -1,7 +1,5 @@
{% macro wpoll(poll) %}
{% set n_answers = len(poll.answers) %}
{% import "widgets/polls/"+poll.template as poll_template with context %}
<div class="poll">
@ -12,20 +10,21 @@
{# Poll has ended: display results #}
{% elif poll.ended %}
<div>Ce sondage est terminé. Voici les résultats des {{ n_answers }} participation{{ n_answers | pluralize }}.</div>
{{ poll_template.results(poll) }}
<p><i>Ce sondage est terminé.</i></p>
{# Current user is a guest #}
{% elif not current_user.is_authenticated %}
<p><i>Seuls les membres peuvent voter</i></p>
<p><i>Seuls les membres peuvent voter.</i></p>
{# Current user cannot vote #}
{% elif not poll.can_vote(current_user) %}
<p><i>Vous n'avez pas le droit de voter dans ce sondage. Désolé…</i></p>
<p><i>Vous n'avez pas le droit de voter dans ce sondage.</i></p>
{# Current user has already voted #}
{% elif poll.has_voted(current_user) %}
<p><i>Vous avez déjà voté. Revenez le {{ poll.end | date }} pour voir les résultats</i></p>
{{ poll_template.results(poll) }}
<p><i>Vous avez déjà voté.</i></p>
{# Current user can vote #}
{% else %}

View File

@ -1,8 +1,8 @@
{% macro choices(poll) %}
<fieldset>
{% for choice in poll.choices %}
<input type="radio" id="{{ poll.id }}-{{ choice.id }}" name="pollanwsers" value="{{ choice.id }}" />
<label for="{{ poll.id }}-{{ choice.id }}">{{ choice.title }}</label><br/>
<input type="radio" id="poll{{ poll.id }}-{{ choice.id }}" name="pollanwsers" value="{{ choice.id }}" />
<label for="poll{{ poll.id }}-{{ choice.id }}">{{ choice.title }}</label><br/>
{% endfor %}
</fieldset>
{% endmacro %}
@ -11,13 +11,15 @@
<table>
{% for choice, votes in poll.results.most_common() %}
<tr>
<td><label for="{{ poll.id }}-{{ choice.id }}">{{ choice.title }}</label></td>
<td><label for="poll{{ poll.id }}-{{ choice.id }}">{{ choice.title }}</label></td>
<td>
<progress id="{{ poll.id }}-{{ choice.id }}" value="{{ votes }}" max="{{ n_answers }}">
{{ votes / n_answers if n_answers else 0 }}% ({{ votes }})
</progress>
<progress id="poll{{ poll.id }}-{{ choice.id }}" value="{{ votes }}" max="{{ len(poll.answers) }}"></progress>
</td>
<td>{{ votes }}</td>
</tr>
{% endfor %}
<tr>
<th>Participations</th><th></th><th>{{ len(poll.answers) }}</th>
</tr>
</table>
{% endmacro %}