templates: Check vote against truth id, not number
I made a choice to only log confirmed votes : there is no blank vote in the database. This means that when fetching a user's vote, if they have not voted for everyone there will be votes missing. As this is sent to the templating engine via a Vector, the ordering of the votes will be incorrect : all existing votes will follow each other, and there will be missing votes at the end. Update the select logic in the truth template to account for that by checking the truth_id directly, rather than via the index of the array. (O(N²)...) Remove 'has_vote' as this is not useful anymore.
This commit is contained in:
parent
2b3dd28fed
commit
207ce6c1d2
2 changed files with 8 additions and 13 deletions
|
@ -12,13 +12,6 @@
|
||||||
<script defer="defer" type="text/javascript" src="/vote_chart.js"></script>
|
<script defer="defer" type="text/javascript" src="/vote_chart.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
{# Check if the user has a vote in advance, for readability #}
|
|
||||||
{% if user.logged_in == true and user.has_week_vote == true%}
|
|
||||||
{% set has_vote = true %}
|
|
||||||
{% else %}
|
|
||||||
{% set has_vote = false %}
|
|
||||||
{% endif -%}
|
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="top_bar">
|
<div class="top_bar">
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
|
@ -78,7 +71,7 @@
|
||||||
{% if user.logged_in == true and user.is_admin == false %}
|
{% if user.logged_in == true and user.is_admin == false %}
|
||||||
<br/>
|
<br/>
|
||||||
<button form="truths">
|
<button form="truths">
|
||||||
{%- if has_vote == true -%}
|
{%- if user.logged_in == true and user.has_week_vote == true -%}
|
||||||
Changer de vote
|
Changer de vote
|
||||||
{% else %}
|
{% else %}
|
||||||
À voter !
|
À voter !
|
||||||
|
|
|
@ -12,11 +12,13 @@
|
||||||
<option value="0">---</option>
|
<option value="0">---</option>
|
||||||
{% for player in other_players %}
|
{% for player in other_players %}
|
||||||
{# Check if we should pre-select an existing vote #}
|
{# Check if we should pre-select an existing vote #}
|
||||||
{% if has_vote == true and player.id == user.votes[truth_index].voted_id %}
|
{% set_global is_selected = "" %}
|
||||||
{% set is_selected = "selected" %}
|
{% for vote in user.votes %}
|
||||||
{% else %}
|
{% if truth.id == vote.truth_id and player.id == vote.voted_id %}
|
||||||
{% set is_selected = "" %}
|
{% set_global is_selected = "selected" %}
|
||||||
{% endif %}
|
{% break %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
<option value="{{ player.id }}" {{- is_selected -}}>{{ player.name }}</option>
|
<option value="{{ player.id }}" {{- is_selected -}}>{{ player.name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|
Loading…
Add table
Reference in a new issue