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 fed51f6b1b147e7b5e45a4350816b3820f9fdd24..53e52c987c74219ebd0129ea9a503cd4f8d3648b 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 4500988977b03261abd77c594d1ad82804a9f631..2eb5eb4359393a1316d642d1ec91d4f8efb35f16 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 48fb319dbb5a082570d14b6c8d42dec5791a3685..df7022cfa6711b8f8b3f64bed5eb8eb70cd6105c 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}) + )