diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html b/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html index 78cb9ec659023aa753f02899dcafdb6c489e4f5d..6193198511c448e8a343ddb84670dd427e4c1246 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html @@ -4,17 +4,26 @@ <div id="nomination-{{ voting_round.id }}-decision"> {% if voting_round.decision %} + <div class="row"> + <div class="col-auto"> + <h3>Decision</h3> + + {% if voting_round.decision.outcome == 'elected' %} + <div class="badge fs-5 mb-2 bg-success">{{ voting_round.decision.get_outcome_display }}</div> + {% elif voting_round.decision.outcome == 'notelected' %} + <div class="badge fs-5 mb-2 bg-danger">{{ voting_round.decision.get_outcome_display }}</div> + {% endif %} - {% if voting_round.decision.outcome == 'elected' %} - <div class="badge fs-5 mb-2 bg-success">{{ voting_round.decision.get_outcome_display }}</div> - {% elif voting_round.decision.outcome == 'notelected' %} - <div class="badge fs-5 mb-2 bg-danger">{{ voting_round.decision.get_outcome_display }}</div> - {% endif %} + </div> - {% if voting_round.decision.comments %} - <h4>Decision comments</h4> - <p>{{ voting_round.decision.comments }}</p> - {% endif %} + {% comment %} {% if voting_round.decision.comments %} {% endcomment %} + <div class="col"> + <h4>Decision comments</h4> + <p>{{ voting_round.decision.comments }}</p> + </div> + {% comment %} {% endif %} {% endcomment %} + + </div> {% else %} @@ -25,18 +34,18 @@ {% elif voting_round.is_scheduled %} <p class="text-warning">The voting round is scheduled but has not yet started.</p> {% elif voting_round.is_unscheduled %} - <p class="text-warning">The voting round is not yet scheduled.</p> + <p class="text-warning">The voting round is not yet scheduled.</p> {% else %} {% with blocks=voting_round.decision_blocks %} - {% if blocks %} - <p>The decision cannot be fixed at this moment: {{ blocks }}</p> - {% else %} - <form hx-post="{% url 'colleges:_hx_nomination_decision_form' round_id=voting_round.id %}" - hx-target="#nomination-{{ voting_round.id }}-decision"> - {% crispy decision_form %} - </form> - {% endif %} + {% if blocks %} + <p>The decision cannot be fixed at this moment: {{ blocks }}</p> + {% else %} + <form hx-post="{% url 'colleges:_hx_nomination_decision_form' round_id=voting_round.id %}" + hx-target="#nomination-{{ voting_round.id }}-decision"> + {% crispy decision_form %} + </form> + {% endif %} {% endwith %} {% endif %} diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_voter_table.html b/scipost_django/colleges/templates/colleges/_hx_nomination_voter_table.html index ba7b5587e5f6f9954e667b8d7c3dc747d728f368..b56ba572e4982a534ca5d93d9ad168a9a71c6c80 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_voter_table.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_voter_table.html @@ -3,8 +3,13 @@ <thead class="table-light"> <tr> <th>Fellow</th> - <th>Vote</th> - <th>Voted on</th> + <th>Specialties</th> + + {% if not round.is_unscheduled %} + <th>Vote</th> + <th>Voted on</th> + {% endif %} + <th>Actions</th> </tr> </thead> @@ -15,26 +20,46 @@ <tr> <td>{{ voter }}</td> - {% if voter.vote.vote == "agree" %} - <td class="text-success">{{ voter.vote.get_vote_display }}</td> - {% elif voter.vote.vote == "abstain" %} - <td class="text-warning">{{ voter.vote.get_vote_display }}</td> - {% elif voter.vote.vote == "disagree" %} - <td class="text-danger">{{ voter.vote.get_vote_display }}</td> - {% elif voter.vote.vote == "veto" %} - <td> - <span class="badge bg-dark">{{ voter.vote.get_vote_display }}</span> - </td> - {% else %} - <td class="text-muted">No vote</td> - {% endif %} + <td> - <td>{{ voter.vote.on }}</td> + {% for specialty in voter.contributor.profile.specialties.all %} + <div class="single d-inline + {% if specialty in nominee_specialties %}text-primary{% endif %} + " data-specialty="{{ specialty.slug }}" data-bs-placement="bottom" title="{{ specialty }}"> + {{ specialty.code }} + </div> + {% endfor %} + + + </td> + + {% if not round.is_unscheduled %} + + {% if voter.vote.vote == "agree" %} + <td class="text-success">{{ voter.vote.get_vote_display }}</td> + {% elif voter.vote.vote == "abstain" %} + <td class="text-warning">{{ voter.vote.get_vote_display }}</td> + {% elif voter.vote.vote == "disagree" %} + <td class="text-danger">{{ voter.vote.get_vote_display }}</td> + {% elif voter.vote.vote == "veto" %} + <td> + <span class="badge bg-dark">{{ voter.vote.get_vote_display }}</span> + </td> + {% else %} + <td class="text-muted">No vote</td> + {% endif %} + + <td>{{ voter.vote.on }}</td> + {% endif %} <td> {% if not round.is_closed %} - <a class="btn btn-sm btn-danger px-1 py-0 ms-auto">{% include "bi/trash-fill.html" %}</a> + <button class="btn btn-sm btn-danger px-1 py-0 ms-auto" + hx-get="{% url "colleges:_hx_nomination_round_eligible_voter_action" round_id=round.id fellowship_id=voter.id action='remove' %}" + hx-target="#nomination-{{ round.nomination.id }}-round-{{ round.id }}-voters"> + {% include "bi/trash-fill.html" %} + </button> {% endif %} </td> @@ -42,6 +67,7 @@ {% endfor %} + </tbody> </table> {% else %} diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_voting_rounds_tab.html b/scipost_django/colleges/templates/colleges/_hx_nomination_voting_rounds_tab.html index 6d9dd5649c2ed48d5115294358328442dce8f1e8..a2369526bb40aafa244dea2c959e9fd5d6febde4 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_voting_rounds_tab.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_voting_rounds_tab.html @@ -48,7 +48,7 @@ {% if selected_round %} <div id="nomination-{{ nomination_id }}-round-{{ selected_round.id }}-tab-content-holder" class="mt-3 px-3"> - {% include "colleges/_hx_voting_round_details.html" with voting_round=selected_round round_start_form=round_start_form %} + {% include "colleges/_hx_voting_round_details.html" with voting_round=selected_round round_start_form=round_start_form new_voter_form=new_voter_form %} </div> {% endif %} 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 6ff4316bbbade0c89f6202cf947bb39494593dc2..fed51f6b1b147e7b5e45a4350816b3820f9fdd24 100644 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html +++ b/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html @@ -3,7 +3,7 @@ <div class="row"> <div class="col"> <h3>Eligible voters</h3> - <div id="nomination-{{ nomination.id }}-round-{{ voting_round.id }}-votes" + <div id="nomination-{{ voting_round.nomination.id }}-round-{{ voting_round.id }}-voters" hx-get="{% url 'colleges:_hx_nomination_voter_table' round_id=voting_round.id %}" hx-trigger="intersect once"></div> </div> @@ -11,10 +11,15 @@ {% if "edadmin" in user_roles and not voting_round.is_closed %} <div class="col-4"> <h4>Add new voter</h4> - <h4>Add senior fellows</h4> + <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> + </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> - {{ form }} </div> {% endif %} @@ -23,11 +28,8 @@ {% if voting_round.is_closed %} <div class="row mb-0"> <div class="col-12 col-md mt-3"> - <h3>Decision</h3> - <div hx-get="{% url 'colleges:_hx_nomination_decision_form' round_id=voting_round.id %}" hx-trigger="intersect once"></div> - </div> <div class="col-auto mt-3">{% include "colleges/_voting_results_box.html" with voting_round=voting_round %}</div> </div> diff --git a/scipost_django/colleges/urls.py b/scipost_django/colleges/urls.py index d982355533a56806c686d436a95d4e308c5a569d..4500988977b03261abd77c594d1ad82804a9f631 100644 --- a/scipost_django/colleges/urls.py +++ b/scipost_django/colleges/urls.py @@ -244,19 +244,24 @@ urlpatterns = [ ), # Manage voters of a nomination round path( - "voter/<int:voter_id>/", + "voter/<int:fellowship_id>/", include( [ - path( - "remove", - views._hx_nomination_round_remove_voter, - name="_hx_nomination_round_remove_voter", - ), + # 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>", + views._hx_nomination_round_eligible_voter_action, + name="_hx_nomination_round_eligible_voter_action", + ), ] ), ), diff --git a/scipost_django/colleges/views.py b/scipost_django/colleges/views.py index 2874e04ed66557433728cb9ab2416b43c155a10e..48fb319dbb5a082570d14b6c8d42dec5791a3685 100644 --- a/scipost_django/colleges/views.py +++ b/scipost_django/colleges/views.py @@ -921,12 +921,22 @@ def _hx_nomination_voting_rounds_tab(request, nomination_id, round_id): selected_round = voting_rounds.get(id=round_id) context["selected_round"] = selected_round - if not round.is_closed(): + if not selected_round.is_closed: round_start_form = FellowshipNominationVotingRoundStartForm( request.POST or None, instance=selected_round, ) + voter_add_form = FellowshipDynSelForm( + initial={ + "action_url_name": "colleges:_hx_nomination_round_eligible_voter_action", + "action_url_base_kwargs": {"round_id": round_id, "action": "add"}, + "action_target_element_id": f"nomination-{nomination_id}-round-{round_id}-voters", + "action_target_swap": "innerHTML", + } + ) + context["voter_add_form"] = voter_add_form + if round_start_form.is_valid(): round_start_form.save() messages.success( @@ -1246,6 +1256,7 @@ def _hx_fellowship_invitation_update_response(request, invitation_id): def _hx_nomination_voter_table(request, round_id): round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id) voters = round.eligible_to_vote.all() + nominee_specialties = round.nomination.profile.specialties.all() for voter in voters: voter.vote = round.votes.filter(fellow=voter).first() @@ -1253,6 +1264,7 @@ def _hx_nomination_voter_table(request, round_id): context = { "voters": voters, "round": round, + "nominee_specialties": nominee_specialties, } return render(request, "colleges/_hx_nomination_voter_table.html", context) @@ -1262,6 +1274,7 @@ 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":