SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit cb91ab47 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add removal of voter from nomination round

parent 2fabdf28
No related branches found
No related tags found
1 merge request!58[Fellowship Nominations] Rework the fellowship nomination system and UI
<h4>Eligible Voters</h4> <h4>Eligible Voters</h4>
{% include 'colleges/_hx_nomination_eligible_voters_table.html' with eligible_voters=eligible_voters %} {% include 'colleges/_hx_nomination_eligible_voters_table.html' with round=round %}
{% if eligible_voters|length > 0 %} {% with round.eligible_to_vote.all|length as nr_voters %}
<button id="nomination-{{ nomination.id }}-start-round-btn"
hx-get="{% url 'colleges:_hx_nomination_round_start' nomination_id=nomination.id %}" {% if nr_voters > 0 %}
hx-target="#nomination-{{ nomination.id }}-eligible-voters" <div class="d-flex justify-content-between">
class="nomination-start-round-btn btn btn-{% if eligible_voters|length < 5 %}warning{% else %}primary{% endif %}" <button id="nomination-{{ nomination.id }}-start-round-btn"
{% if eligible_voters|length < 5 %}hx-confirm="Are you sure you want to start a round with fewer than 5 voters?"{% endif %} class="nomination-start-round-btn btn btn-{% if nr_voters < 5 %}warning{% else %}primary{% endif %}"
>Start round</button> hx-get="{% url 'colleges:_hx_nomination_round_start' nomination_id=nomination.id %}" hx-target="#nomination-{{ nomination.id }}-eligible-voters"
{% endif %} {% if nr_voters < 5 %}hx-confirm="Are you sure you want to start a round with fewer than 5 voters?"{% endif %}
>Start round</button>
<span class="fs-5 border-top border-dark pt-2">Total: {{ nr_voters }}</span>
</div>
{% endif %}
{% endwith %}
{% if eligible_voters %} {% if round.eligible_to_vote.all %}
<table class="table"> <table class="table">
<thead class="table-light"> <thead class="table-light">
<tr> <tr>
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
<th>College</th> <th>College</th>
<th>Specialties</th> <th>Specialties</th>
<th>Type</th> <th>Type</th>
<th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for voter in eligible_voters %} {% for voter in round.eligible_to_vote.all %}
<tr> <tr class="align-middle">
<td>{{ voter.contributor }}</td> <td>{{ voter.contributor }}</td>
<td>{{ voter.college.name }}</td> <td>{{ voter.college.name }}</td>
<td> <td>
...@@ -28,6 +29,13 @@ ...@@ -28,6 +29,13 @@
</td> </td>
<td>{{ voter.get_status_display }}</td> <td>{{ voter.get_status_display }}</td>
{% comment %} Actions {% endcomment %}
<td class="text-end">
<a class="btn btn-sm btn-danger"
role="button"
hx-get="{% url 'colleges:_hx_nomination_round_remove_voter' round_id=round.id voter_id=voter.id %}"
hx-target="closest tr"><small>{% include 'bi/trash-fill.html' %}</small></a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
......
...@@ -195,14 +195,10 @@ urlpatterns = [ ...@@ -195,14 +195,10 @@ urlpatterns = [
name="_hx_nominations_no_round_started", name="_hx_nominations_no_round_started",
), ),
path( path(
"_hx_nomination_eligible_voters/<int:nomination_id>",
views._hx_nomination_eligible_voters,
name="_hx_nomination_eligible_voters",
),
path( path(
"_hx_nomination_round_start/<int:nomination_id>", "<int:round_id>/_hx_nomination_round_remove_voter/<int:voter_id>",
views._hx_nomination_round_start, views._hx_nomination_round_remove_voter,
name="_hx_nomination_round_start", name="_hx_nomination_round_remove_voter",
), ),
path( path(
"_hx_voting_rounds", "_hx_voting_rounds",
......
...@@ -788,6 +788,7 @@ def _hx_nomination_eligible_voters(request, nomination_id): ...@@ -788,6 +788,7 @@ def _hx_nomination_eligible_voters(request, nomination_id):
"nomination": nomination, "nomination": nomination,
"eligible_voters": eligible_voters, "eligible_voters": eligible_voters,
"nominee_specialties": nomination.profile.specialties.all(), "nominee_specialties": nomination.profile.specialties.all(),
"round": nomination.voting_rounds.first(),
} }
return render( return render(
request, request,
...@@ -796,6 +797,22 @@ def _hx_nomination_eligible_voters(request, nomination_id): ...@@ -796,6 +797,22 @@ def _hx_nomination_eligible_voters(request, nomination_id):
) )
def _hx_nomination_round_remove_voter(request, round_id, voter_id):
"""Remove a voter from a nomination's voting round."""
round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id)
voter = get_object_or_404(Fellowship, pk=voter_id)
if voter in round.eligible_to_vote.all():
round.eligible_to_vote.remove(voter)
round.save()
messages.success(
request, f"Removed {voter} from the voters list of this round."
)
else:
messages.error(request, f"{voter} was not in the voters list of this round.")
return HttpResponse("")
def _hx_nomination_round_start(request, nomination_id): def _hx_nomination_round_start(request, nomination_id):
"""Create a voting round for the specified nomination using the default eligible voters.""" """Create a voting round for the specified nomination using the default eligible voters."""
nomination = get_object_or_404(FellowshipNomination, pk=nomination_id) nomination = get_object_or_404(FellowshipNomination, pk=nomination_id)
......
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