SciPost Code Repository

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

add multiple voters to nomination rounds

parent e9f56a4c
No related branches found
No related tags found
1 merge request!58[Fellowship Nominations] Rework the fellowship nomination system and UI
...@@ -14,12 +14,24 @@ ...@@ -14,12 +14,24 @@
<form hx-post="{% url 'colleges:_hx_fellowship_dynsel_list' %}" <form hx-post="{% url 'colleges:_hx_fellowship_dynsel_list' %}"
hx-trigger="keyup delay:200ms, change" hx-trigger="keyup delay:200ms, change"
hx-target="#nomination-{{ voting_round.nomination.id }}_round-{{ voting_round.id }}_add_voter_results"> hx-target="#nomination-{{ voting_round.nomination.id }}_round-{{ voting_round.id }}_add_voter_results">
<div id="nomination-{{ voting_round.nomination.id }}_round-{{ voting_round.id }}_add_voter_form">{% crispy voter_add_form %}</div> <div id="nomination-{{ voting_round.nomination.id }}_round-{{ voting_round.id }}_add_voter_form">
{% crispy voter_add_form %}
</div>
</form> </form>
<div id="nomination-{{ voting_round.nomination.id }}_round-{{ voting_round.id }}_add_voter_results"></div> <div id="nomination-{{ voting_round.nomination.id }}_round-{{ voting_round.id }}_add_voter_results"></div>
<h5>Add senior fellows</h5> <h5>Add senior fellows</h5>
<button type="button" class="mb-2 btn btn-primary btn-sm">With specialty overlap</button> <button type="button"
<button type="button" class="mb-2 btn btn-warning text-white btn-sm">ALL seniors</button> class="mb-2 btn btn-primary btn-sm"
hx-get="{% url 'colleges:_hx_nomination_round_add_eligible_voter_set' round_id=voting_round.id voter_set_name='with_specialty_overlap' %}"
hx-target="#nomination-{{ voting_round.nomination.id }}-round-{{ voting_round.id }}-voters">
With specialty overlap
</button>
<button type="button"
class="mb-2 btn btn-warning text-white btn-sm"
hx-get="{% url 'colleges:_hx_nomination_round_add_eligible_voter_set' round_id=voting_round.id voter_set_name='all_seniors' %}"
hx-target="#nomination-{{ voting_round.nomination.id }}-round-{{ voting_round.id }}-voters">
ALL seniors
</button>
</div> </div>
{% endif %} {% endif %}
......
...@@ -244,24 +244,19 @@ urlpatterns = [ ...@@ -244,24 +244,19 @@ urlpatterns = [
), ),
# Manage voters of a nomination round # Manage voters of a nomination round
path( path(
"voter/<int:fellowship_id>/", "voters/",
include( include(
[ [
# path(
# "remove",
# views._hx_nomination_round_remove_voter,
# name="_hx_nomination_round_remove_voter",
# ),
# path(
# "add",
# views._hx_nomination_round_add_voter,
# name="_hx_nomination_round_add_voter",
# ),
path( path(
"action/<str:action>", "/<int:fellowship_id>/action/<str:action>",
views._hx_nomination_round_eligible_voter_action, views._hx_nomination_round_eligible_voter_action,
name="_hx_nomination_round_eligible_voter_action", name="_hx_nomination_round_eligible_voter_action",
), ),
path(
"add_set/<str:voter_set_name>",
views._hx_nomination_round_add_eligible_voter_set,
name="_hx_nomination_round_add_eligible_voter_set",
),
] ]
), ),
), ),
......
...@@ -1274,7 +1274,6 @@ def _hx_nomination_voter_table(request, round_id): ...@@ -1274,7 +1274,6 @@ def _hx_nomination_voter_table(request, round_id):
def _hx_nomination_round_eligible_voter_action( def _hx_nomination_round_eligible_voter_action(
request, round_id, fellowship_id, action request, round_id, fellowship_id, action
): ):
print(f"receieved {action} for {fellowship_id} in {round_id}")
round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id) round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id)
fellowship = get_object_or_404(Fellowship, pk=fellowship_id) fellowship = get_object_or_404(Fellowship, pk=fellowship_id)
if action == "add": if action == "add":
...@@ -1284,3 +1283,29 @@ def _hx_nomination_round_eligible_voter_action( ...@@ -1284,3 +1283,29 @@ def _hx_nomination_round_eligible_voter_action(
return redirect( return redirect(
reverse("colleges:_hx_nomination_voter_table", kwargs={"round_id": round.id}) reverse("colleges:_hx_nomination_voter_table", kwargs={"round_id": round.id})
) )
@login_required
@user_passes_test(is_edadmin)
def _hx_nomination_round_add_eligible_voter_set(request, round_id, voter_set_name):
round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id)
voter_set = Fellowship.objects.none()
if voter_set_name == "with_specialty_overlap":
specialties_slug_list = [
s.slug for s in round.nomination.profile.specialties.all()
]
voter_set = (
Fellowship.objects.active()
.senior()
.specialties_overlap(specialties_slug_list)
.distinct()
)
elif voter_set_name == "all_seniors":
voter_set = Fellowship.objects.active().senior().distinct()
round.eligible_to_vote.add(*voter_set)
return redirect(
reverse("colleges:_hx_nomination_voter_table", kwargs={"round_id": round.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