PCv5/app/templates/widgets/poll.html

38 lines
1.4 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{% macro poll(p) %}
<div class="poll">
<p><strong>{{ p.title }}</strong></p>
{# Poll has ended: display results #}
{% if p.ended %}
<table>
{% for choice, votes in p.results.most_common() %}
<tr>
<td><label for="{{ poll.id }}-{{ loop.index }}">{{ choice }}</label></td>
<td>
<progress id="{{ poll.id }}-{{ loop.index }}" value="{{ votes }}" max="{{ p.answers.count() }}">
{{ votes / p.answers.count() }}% ({{ votes }})
</progress>
</td>
</tr>
{% endfor %}
</table>
{# Current user has already voted #}
{% elif p.has_voted(current_user) %}
<p><i>Vous avez déjà voté. Revenez plus tard pour voir les résultats</i></p>
{# Current user is a guest #}
{% elif not current_user.is_authenticated %}
<p><i>Seuls les membres peuvent voter</i></p>
{# Current user can vote #}
{% else %}
<form class="poll" action="" method="post" enctype="multipart/form-data">
<fieldset>
{% for choice in p.choices %}
<input type="{{ 'radio' if poll.type == 1 else 'checkbox' }}" id="{{ poll.id }}-{{ loop.index }}" name="pollanwsers" value="{{ choice }}" />
<label for="{{ poll.id }}-{{ loop.index }}">{{ choice }}</label><br>
{% endfor %}
</fieldset>
<input type="submit" value="Envoyer">
</form>
{% endif %}
</div>
{% endmacro %}