SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit d4dde186 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Fix bug in meeting voting (by ensuring unique element identifiers)

parent 85749615
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th>Eligible to vote</th> <th>Eligible for voting</th>
<th>Agreed</th> <th>Agreed</th>
<th>Doubt</th> <th>Doubt</th>
<th>Disagreed</th> <th>Disagreed</th>
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<tr> <tr>
<td> <td>
<ul class="list list-unstyled"> <ul class="list list-unstyled">
{% for voter in motion.eligible_to_vote.all %} {% for voter in motion.eligible_for_voting.all %}
<li>{{ voter.contributor }}</li> <li>{{ voter.contributor }}</li>
{% empty %} {% empty %}
<li>None</li> <li>None</li>
...@@ -107,75 +107,77 @@ ...@@ -107,75 +107,77 @@
{% endfor %} {% endfor %}
{% endif %} {% endif %}
<form hx-post="{% url 'forums:_hx_motion_voting' slug=forum.slug motion_id=motion.id %}" <form id="motion-{{ motion.id }}-voting-form"
hx-post="{% url 'forums:_hx_motion_voting' slug=forum.slug motion_id=motion.id %}"
hx-target="#motion-{{ motion.id }}-voting" hx-target="#motion-{{ motion.id }}-voting"
hx-trigger="change" hx-trigger="change"
> >
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="user" value="{{ request.user.id }}" id="id_user"> <input type="hidden" name="user" value="{{ request.user.id }}" id="motion-{{ motion.id }}-id_user">
<input type="hidden" name="motion" value="{{ motion.id }}" id="id_motion"> <input type="hidden" name="motion" value="{{ motion.id }}" id="motion-{{ motion.id }}-id_motion">
<div class="btn-group" role="group" aria-label="motion voting buttons"> <div id="motion-{{ motion.id }}-voting-options"
class="btn-group" role="group" aria-label="motion voting buttons">
<input type="radio" class="btn-check" name="vote" <input type="radio" class="btn-check" name="vote"
id="vote-Y" value="Y" id="motion-{{ motion.id }}-vote-Y" value="Y"
{% if request.user in motion.in_agreement.all %}checked{% endif %} {% if request.user in motion.in_agreement.all %}checked{% endif %}
{% if not motion.open_for_voting or request.user not in motion.eligible_for_voting.all %}disabled {% if not motion.open_for_voting or request.user not in motion.eligible_for_voting.all %}disabled
{% endif %} {% endif %}
> >
{% if request.user in motion.in_agreement.all %} {% if request.user in motion.in_agreement.all %}
<label class="btn btn-success text-white" for="vote-Y"> <label class="btn btn-success text-white" for="motion-{{ motion.id }}-vote-Y">
<strong>Agree&nbsp;{% include "bi/check-square-fill.html" %}</strong> <strong>Agree&nbsp;{% include "bi/check-square-fill.html" %}</strong>
<br>{{ motion.in_agreement.all|length }} <br>{{ motion.in_agreement.all|length }}
</label> </label>
{% else %} {% else %}
<label class="btn btn-success" for="vote-Y"> <label class="btn btn-success" for="motion-{{ motion.id }}-vote-Y">
Agree&nbsp;{% include "bi/square.html" %} Agree&nbsp;{% include "bi/square.html" %}
<br>{{ motion.in_agreement.all|length }} <br>{{ motion.in_agreement.all|length }}
</label> </label>
{% endif %} {% endif %}
<input type="radio" class="btn-check" name="vote" <input type="radio" class="btn-check" name="vote"
id="vote-M" value="M" id="motion-{{ motion.id }}-vote-M" value="M"
{% if request.user in motion.in_doubt.all %}checked{% endif %} {% if request.user in motion.in_doubt.all %}checked{% endif %}
{% if not motion.open_for_voting or request.user not in motion.eligible_for_voting.all %}disabled {% if not motion.open_for_voting or request.user not in motion.eligible_for_voting.all %}disabled
{% endif %} {% endif %}
> >
{% if request.user in motion.in_doubt.all %} {% if request.user in motion.in_doubt.all %}
<label class="btn btn-warning text-white" for="vote-M"> <label class="btn btn-warning text-white" for="motion-{{ motion.id }}-vote-M">
<strong>Doubt&nbsp;{% include "bi/check-square-fill.html" %}</strong> <strong>Doubt&nbsp;{% include "bi/check-square-fill.html" %}</strong>
<br>{{ motion.in_doubt.all|length }} <br>{{ motion.in_doubt.all|length }}
</label> </label>
{% else %} {% else %}
<label class="btn btn-warning" for="vote-M"> <label class="btn btn-warning" for="motion-{{ motion.id }}-vote-M">
Doubt&nbsp;{% include "bi/square.html" %} Doubt&nbsp;{% include "bi/square.html" %}
<br>{{ motion.in_doubt.all|length }} <br>{{ motion.in_doubt.all|length }}
</label> </label>
{% endif %} {% endif %}
<input type="radio" class="btn-check" name="vote" <input type="radio" class="btn-check" name="vote"
id="vote-N" value="N" id="motion-{{ motion.id }}-vote-N" value="N"
{% if request.user in motion.in_disagreement.all %}checked{% endif %} {% if request.user in motion.in_disagreement.all %}checked{% endif %}
{% if not motion.open_for_voting or request.user not in motion.eligible_for_voting.all %}disabled {% if not motion.open_for_voting or request.user not in motion.eligible_for_voting.all %}disabled
{% endif %} {% endif %}
> >
{% if request.user in motion.in_disagreement.all %} {% if request.user in motion.in_disagreement.all %}
<label class="btn btn-danger text-white" for="vote-N"> <label class="btn btn-danger text-white" for="motion-{{ motion.id }}-vote-N">
<strong>Disagree&nbsp;{% include "bi/check-square-fill.html" %}</strong> <strong>Disagree&nbsp;{% include "bi/check-square-fill.html" %}</strong>
<br>{{ motion.in_disagreement.all|length }} <br>{{ motion.in_disagreement.all|length }}
</label> </label>
{% else %} {% else %}
<label class="btn btn-danger text-dark" for="vote-N"> <label class="btn btn-danger text-dark" for="motion-{{ motion.id }}-vote-N">
Disagree&nbsp;{% include "bi/square.html" %} Disagree&nbsp;{% include "bi/square.html" %}
<br>{{ motion.in_disagreement.all|length }} <br>{{ motion.in_disagreement.all|length }}
</label> </label>
{% endif %} {% endif %}
<input type="radio" class="btn-check" name="vote" <input type="radio" class="btn-check" name="vote"
id="vote-A" value="A" id="motion-{{ motion.id }}-vote-A" value="A"
{% if request.user in motion.in_abstain.all %}checked{% endif %} {% if request.user in motion.in_abstain.all %}checked{% endif %}
{% if not motion.open_for_voting or request.user not in motion.eligible_for_voting.all %}disabled {% if not motion.open_for_voting or request.user not in motion.eligible_for_voting.all %}disabled
{% endif %} {% endif %}
> >
<label class="btn btn-secondary" for="vote-A"> <label class="btn btn-secondary" for="motion-{{ motion.id }}-vote-A">
Abstain&nbsp; Abstain&nbsp;
{% if request.user in motion.in_abstain.all %} {% if request.user in motion.in_abstain.all %}
{% include "bi/check-square-fill.html" %} {% include "bi/check-square-fill.html" %}
......
...@@ -294,7 +294,6 @@ def _hx_post_form(request, slug, parent_model, parent_id, origin, target, text): ...@@ -294,7 +294,6 @@ def _hx_post_form(request, slug, parent_model, parent_id, origin, target, text):
response["HX-Trigger-After-Settle"] = json.dumps( response["HX-Trigger-After-Settle"] = json.dumps(
{"newPost": f"thread-{thread_initiator.id}",} {"newPost": f"thread-{thread_initiator.id}",}
) )
print(f'{response["HX-Trigger-After-Settle"] = }')
return response return response
else: else:
subject = "" subject = ""
...@@ -409,8 +408,8 @@ def _hx_motion_voting(request, slug, motion_id): ...@@ -409,8 +408,8 @@ def _hx_motion_voting(request, slug, motion_id):
"in_abstain__contributor__user", "in_abstain__contributor__user",
), pk=motion_id) ), pk=motion_id)
initial = { initial = {
"user": request.user.id, "user": request.user,
"motion": motion.id, "motion": motion,
} }
form = MotionVoteForm(request.POST or None, initial=initial) form = MotionVoteForm(request.POST or None, initial=initial)
if form.is_valid(): if form.is_valid():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment