38 lines
1.4 KiB
HTML
38 lines
1.4 KiB
HTML
{% 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 %}
|