From 7d4c70b209a73ff709c78e4be5a86e5f720b275d Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 26 Sep 2023 19:15:55 +0200 Subject: [PATCH] add multiple voters to nomination rounds --- .../colleges/_hx_voting_round_details.html | 18 ++++++++++--- scipost_django/colleges/urls.py | 19 +++++-------- scipost_django/colleges/views.py | 27 ++++++++++++++++++- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html b/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html index fed51f6b1..53e52c987 100644 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html +++ b/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html @@ -14,12 +14,24 @@ <form hx-post="{% url 'colleges:_hx_fellowship_dynsel_list' %}" hx-trigger="keyup delay:200ms, change" 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> <div id="nomination-{{ voting_round.nomination.id }}_round-{{ voting_round.id }}_add_voter_results"></div> <h5>Add senior fellows</h5> - <button type="button" class="mb-2 btn btn-primary btn-sm">With specialty overlap</button> - <button type="button" class="mb-2 btn btn-warning text-white btn-sm">ALL seniors</button> + <button type="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> {% endif %} diff --git a/scipost_django/colleges/urls.py b/scipost_django/colleges/urls.py index 450098897..2eb5eb435 100644 --- a/scipost_django/colleges/urls.py +++ b/scipost_django/colleges/urls.py @@ -244,24 +244,19 @@ urlpatterns = [ ), # Manage voters of a nomination round path( - "voter/<int:fellowship_id>/", + "voters/", 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( - "action/<str:action>", + "/<int:fellowship_id>/action/<str:action>", views._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", + ), ] ), ), diff --git a/scipost_django/colleges/views.py b/scipost_django/colleges/views.py index 48fb319db..df7022cfa 100644 --- a/scipost_django/colleges/views.py +++ b/scipost_django/colleges/views.py @@ -1274,7 +1274,6 @@ def _hx_nomination_voter_table(request, round_id): def _hx_nomination_round_eligible_voter_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) fellowship = get_object_or_404(Fellowship, pk=fellowship_id) if action == "add": @@ -1284,3 +1283,29 @@ def _hx_nomination_round_eligible_voter_action( return redirect( 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}) + ) -- GitLab