From 20167ab4a10f112976a6d71cc380a36fb1d13764 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Mon, 2 Oct 2023 17:39:56 +0200 Subject: [PATCH] refactor nomination round details outside of tab --- .../_hx_nomination_voting_rounds_tab.html | 19 +++--- .../colleges/_hx_voting_round_details.html | 58 +++++++++---------- scipost_django/colleges/urls.py | 5 ++ scipost_django/colleges/views.py | 37 ++++++++---- 4 files changed, 68 insertions(+), 51 deletions(-) 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 7556a7f4c..11fa485d7 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 @@ -3,12 +3,13 @@ <nav class="nav nav-pills m-2 overflow-scroll"> {% if should_show_new_round_tab_btn %} - <div id="nomination-{{ nomination.id }}-new-round-btn" type="button" class="me-2 px-2 nav-link - {% if new_round %}bg-success{% else %}border border-success{% endif %} - " hx-get="{% url 'colleges:_hx_nomination_voting_rounds_create' nomination_id=nomination.id %}" hx-target="#nomination-{{ nomination.id }}-round-tab-holder" hx-swap="outerHTML"> - <span class="fs-1 align-items-center text- - {% if new_round %}white{% else %}success{% endif %} - ">+</span> + <div id="nomination-{{ nomination.id }}-new-round-btn" + type="button" + class="me-2 px-2 nav-link border border-success" + hx-get="{% url 'colleges:_hx_nomination_voting_rounds_create' nomination_id=nomination.id %}" + hx-target="#nomination-{{ nomination.id }}-round-tab-holder" + hx-swap="outerHTML"> + <span class="fs-1 align-items-center text-success">+</span> </div> {% endif %} @@ -57,9 +58,9 @@ {% if selected_round %} <div id="nomination-{{ nomination.id }}-round-{{ selected_round.id }}-tab-content-holder" - class="p-3"> - {% 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> + hx-get="{% url 'colleges:_hx_voting_round_details' round_id=selected_round.id %}" + hx-trigger="intersect once" + class="p-3"></div> {% endif %} </div> 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 04e8310ef..1fab54c60 100644 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html +++ b/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html @@ -1,52 +1,50 @@ {% load crispy_forms_tags %} +{% load user_groups %} +{% is_ed_admin request.user as is_ed_admin %} <div class="row mb-0"> <div class="col mb-3"> <h3>Eligible voters</h3> - <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 %}" + <div id="nomination-{{ round.nomination.id }}-round-{{ round.id }}-voters" + hx-get="{% url 'colleges:_hx_nomination_voter_table' round_id=round.id %}" hx-trigger="intersect once"></div> </div> <div class="col-12 col-md-auto d-flex flex-column justify-content-between"> - {% if not voting_round.is_closed %} + {% if not round.is_closed %} - {% if "edadmin" in user_roles %} + {% if is_ed_admin %} <div> <h4>Add new voter</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> + hx-target="#nomination-{{ round.nomination.id }}_round-{{ round.id }}_add_voter_results"> + <div id="nomination-{{ round.nomination.id }}_round-{{ 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> + <div id="nomination-{{ round.nomination.id }}_round-{{ round.id }}_add_voter_results"></div> </div> <div> <h5>Add senior fellows</h5> <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"> + hx-get="{% url 'colleges:_hx_nomination_round_add_eligible_voter_set' round_id=round.id voter_set_name='with_specialty_overlap' %}" + hx-target="#nomination-{{ round.nomination.id }}-round-{{ 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> + hx-get="{% url 'colleges:_hx_nomination_round_add_eligible_voter_set' round_id=round.id voter_set_name='all_seniors' %}" + hx-target="#nomination-{{ round.nomination.id }}-round-{{ round.id }}-voters">ALL seniors</button> </div> {% comment %} If round is open and the viewer can vote, show the voting form {% endcomment %} - {% elif session_fellowship and session_fellowship in voting_round.eligible_to_vote.all and voting_round.is_open %} + {% elif session_fellowship and session_fellowship in round.eligible_to_vote.all and round.is_open %} - <div id="nomination-{{ voting_round.nomination.id }}-vote" - hx-get="{% url 'colleges:_hx_nomination_vote' round_id=voting_round.id %}" + <div id="nomination-{{ round.nomination.id }}-vote" + hx-get="{% url 'colleges:_hx_nomination_vote' round_id=round.id %}" hx-trigger="intersect once"></div> {% endif %} @@ -56,19 +54,19 @@ <div>{% include "colleges/_voting_results_box.html" with voting_round=voting_round %}</div> - {% if voting_round.decision %} + {% if round.decision %} <div> <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> + {% if round.decision.outcome == 'elected' %} + <div class="badge fs-5 mb-2 bg-success">{{ round.decision.get_outcome_display }}</div> + {% elif round.decision.outcome == 'notelected' %} + <div class="badge fs-5 mb-2 bg-danger">{{ round.decision.get_outcome_display }}</div> {% endif %} - {% if voting_round.decision.comments %} + {% if round.decision.comments %} <h4 class="mt-2">Decision comments</h4> - <span>{{ voting_round.decision.comments }}</span> + <span>{{ round.decision.comments }}</span> {% endif %} {% endif %} @@ -78,16 +76,16 @@ </div> </div> -{% if "edadmin" in user_roles %} +{% if is_ed_admin %} - {% if not voting_round.is_closed %} + {% if not round.is_closed %} - <div hx-get="{% url 'colleges:_hx_voting_round_start_form' round_id=voting_round.id %}" + <div hx-get="{% url 'colleges:_hx_voting_round_start_form' round_id=round.id %}" hx-trigger="intersect once"></div> - {% elif voting_round.is_closed and not voting_round.decision %} + {% elif round.is_closed and not round.decision %} - <div hx-get="{% url 'colleges:_hx_nomination_decision_form' round_id=voting_round.id %}" + <div hx-get="{% url 'colleges:_hx_nomination_decision_form' round_id=round.id %}" hx-trigger="intersect once"></div> {% endif %} diff --git a/scipost_django/colleges/urls.py b/scipost_django/colleges/urls.py index f24fb4520..21299fad2 100644 --- a/scipost_django/colleges/urls.py +++ b/scipost_django/colleges/urls.py @@ -228,6 +228,11 @@ urlpatterns = [ include( [ path("_hx_vote", views._hx_nomination_vote, name="_hx_nomination_vote"), + path( + "_hx_details", + views._hx_voting_round_details, + name="_hx_voting_round_details", + ), path( "_hx_voter_table", views._hx_nomination_voter_table, diff --git a/scipost_django/colleges/views.py b/scipost_django/colleges/views.py index 713ee63a6..8bc43dcc2 100644 --- a/scipost_django/colleges/views.py +++ b/scipost_django/colleges/views.py @@ -826,24 +826,12 @@ def _hx_nomination_voting_rounds_tab(request, nomination_id, round_id): "voting_rounds": voting_rounds, "inaccessible_round_ids": inaccessible_round_ids, "should_show_new_round_tab_btn": should_show_new_round_tab_btn, - "new_round": False, } if round_id != 0: selected_round = voting_rounds.get(id=round_id) context["selected_round"] = selected_round - if not selected_round.is_closed: - 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 - return render(request, "colleges/_hx_nomination_voting_rounds_tab.html", context) @@ -1163,3 +1151,28 @@ def _hx_nomination_round_add_eligible_voter_set(request, round_id, voter_set_nam return redirect( reverse("colleges:_hx_nomination_voter_table", kwargs={"round_id": round.id}) ) + + +@login_required +@user_passes_test(is_edadmin_or_senior_fellow) +def _hx_voting_round_details(request, round_id): + round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id) + context = { + "round": round, + } + + if not round.can_view(request.user): + return HTMXResponse("You are not allowed to view this round.", tag="danger") + + if not round.is_closed: + 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-{round.nomination.id}-round-{round_id}-voters", + "action_target_swap": "innerHTML", + } + ) + context["voter_add_form"] = voter_add_form + + return render(request, "colleges/_hx_voting_round_details.html", context) -- GitLab