FabulaVotes/templates/weeks/truth.html.tera
trotFunky 1b4a934398 auth: Split off vote data from the user
Now that the application is going to have multiple pages, vote data makes no sense
to keep with the user.
The user struct will be used everywhere to check for authentication, which is not
the case for previous votes.

Create a new struct and function in src/vote.rs to retrieve existing votes and
use them in places where user.votes was used previously.
Remove vote-related code from src/auth.rs and the week number dependence that it
required.
2024-07-28 16:55:22 +01:00

34 lines
1.3 KiB
Text

{%- set is_disabled = "" -%}
{# If we are not during the active week, prevent changing vote but not sending a missing one. #}
{%- if week_data.is_last_week != true and vote_data.votes | filter(attribute="truth_id", value=truth.id) -%}
{%- set is_disabled = "disabled" -%}
{%- endif -%}
<div class="individual_truth">
<h3>Vérité {{ truth.number }}</h3>
<p>{{ truth.rendered_text | safe }}</p>
{% if user.logged_in %}
<hr/>
<label>
{%- if truth.author_id == user.id -%}
Tu l'as fait :)
{%- else -%}
Qui l'a fait ?
<select form="truths" name="truth_votes[{{ truth.id }}]" {{ is_disabled }}>
<option value="0">---</option>
{% for player in other_players %}
{# Check if we should pre-select an existing vote. #}
{% set_global is_selected = "" %}
{% for vote in vote_data.votes %}
{% if truth.id == vote.truth_id and player.id == vote.voted_id %}
{% set_global is_selected = "selected" %}
{% break %}
{% endif %}
{% endfor %}
<option value="{{ player.id }}" {{- is_selected -}}>{{ player.name }}</option>
{% endfor %}
</select>
{%- endif -%}
</label>
{% endif %}
</div>