From 0fcb57b89a8808004e127b234fc865c40fa1b565 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Mon, 2 Oct 2023 17:01:43 +0200 Subject: [PATCH] cleanup old nominations pages and urls --- .../colleges/_hx_nomination_details.html | 2 +- ...l => _hx_nomination_details_contents.html} | 0 .../_hx_nomination_eligible_voters.html | 19 -- .../templates/colleges/_hx_nomination_li.html | 55 ----- ...tions_new.html => _hx_nomination_new.html} | 0 .../colleges/_hx_nomination_vote.html | 2 +- .../_hx_nomination_voting_rounds_tab.html | 14 +- .../templates/colleges/_hx_nominations.html | 22 -- .../colleges/_hx_nominations_invitations.html | 33 --- .../_hx_nominations_invitations_tablist.html | 7 - .../_hx_nominations_needing_specialties.html | 15 -- .../_hx_nominations_no_round_started.html | 16 -- .../colleges/_hx_voting_round_creation.html | 17 -- .../colleges/_hx_voting_round_details.html | 10 +- .../_hx_voting_round_li_contents.html | 19 -- .../colleges/_hx_voting_round_list.html | 24 -- .../colleges/_hx_voting_round_results.html | 17 -- .../colleges/_hx_voting_round_start_form.html | 7 + .../templates/colleges/_hx_voting_rounds.html | 11 - .../colleges/_hx_voting_rounds_tablist.html | 9 - .../templates/colleges/nominations.html | 2 +- scipost_django/colleges/urls.py | 160 ++++++------ scipost_django/colleges/views.py | 228 +++--------------- 23 files changed, 123 insertions(+), 566 deletions(-) rename scipost_django/colleges/templates/colleges/{_hx_nomination_li_contents.html => _hx_nomination_details_contents.html} (100%) delete mode 100644 scipost_django/colleges/templates/colleges/_hx_nomination_eligible_voters.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_nomination_li.html rename scipost_django/colleges/templates/colleges/{_hx_nominations_new.html => _hx_nomination_new.html} (100%) delete mode 100644 scipost_django/colleges/templates/colleges/_hx_nominations.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_nominations_invitations.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_nominations_invitations_tablist.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_nominations_needing_specialties.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_nominations_no_round_started.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_voting_round_creation.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_voting_round_li_contents.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_voting_round_list.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_voting_round_results.html create mode 100644 scipost_django/colleges/templates/colleges/_hx_voting_round_start_form.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_voting_rounds.html delete mode 100644 scipost_django/colleges/templates/colleges/_hx_voting_rounds_tablist.html diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_details.html b/scipost_django/colleges/templates/colleges/_hx_nomination_details.html index e4684a441..fa25047e5 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_details.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_details.html @@ -4,7 +4,7 @@ <div id="nomination-{{ nomination.id }}-details-contents" class="p-2 mt-2 bg-white" - hx-get="{% url 'colleges:_hx_nomination_li_contents' nomination_id=nomination.id %}" + hx-get="{% url 'colleges:_hx_nomination_details_contents' nomination_id=nomination.id %}" hx-trigger="toggle once from:#nomination-{{ nomination.id }}-details"></div> </details> diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_li_contents.html b/scipost_django/colleges/templates/colleges/_hx_nomination_details_contents.html similarity index 100% rename from scipost_django/colleges/templates/colleges/_hx_nomination_li_contents.html rename to scipost_django/colleges/templates/colleges/_hx_nomination_details_contents.html diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_eligible_voters.html b/scipost_django/colleges/templates/colleges/_hx_nomination_eligible_voters.html deleted file mode 100644 index 08fbd3cfc..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_eligible_voters.html +++ /dev/null @@ -1,19 +0,0 @@ -<h4>Eligible Voters</h4> - -{% include 'colleges/_hx_nomination_eligible_voters_table.html' with round=round %} - -{% with round.eligible_to_vote.all|length as nr_voters %} - - {% if nr_voters > 0 %} - <div class="d-flex justify-content-between"> - <button id="nomination-{{ nomination.id }}-start-round-btn" - class="nomination-start-round-btn btn btn-{% if nr_voters < 5 %}warning{% else %}primary{% endif %}" - hx-get="{% url 'colleges:_hx_nomination_round_start' nomination_id=nomination.id %}" hx-target="#nomination-{{ nomination.id }}-eligible-voters" - {% if nr_voters < 5 %}hx-confirm="Are you sure you want to start a round with fewer than 5 voters?"{% endif %} - >Start round</button> - - <span class="fs-5 border-top border-dark pt-2">Total: {{ nr_voters }}</span> - </div> - {% endif %} - -{% endwith %} diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_li.html b/scipost_django/colleges/templates/colleges/_hx_nomination_li.html deleted file mode 100644 index 187f1f54e..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_li.html +++ /dev/null @@ -1,55 +0,0 @@ -<div class="my-2 border border-secondary"> - <details id="nomination-{{ nomination.id }}-li-details"> - <summary class="bg-light p-2 list-triangle container-fluid d-flex"> - - <div class="row mb-0 w-100"> - - <div class="col-12 col-sm"> - <div class="fs-6">{{ nomination.profile }}</div> - <div class="d-none d-md-block">(click for details)</div> - </div> - - {% if nomination.fellowship and nomination.fellowship.is_active %} - <div class="d-none d-md-flex col-auto bg-success text-white my-auto py-1"> - Already - <br /> - Fellow - </div> - {% endif %} - - <div class="col-12 col-sm-auto"> - <div> - <span>Editorial College:</span><span> {{ nomination.college.name }}</span> - </div> - <div> - <span>Nominated on:</span><span> {{ nomination.nominated_on|date:"Y-m-d" }}</span> - </div> - </div> - - <div class="col-12 col-sm-auto"> - <div> - <span>Decision:</span> - - {% if nomination.decision.outcome == "elected" %} - <span class="badge bg-success">{{ nomination.decision.get_outcome_display }}</span> - {% elif nomination.decision.outcome == "notelected" %} - <span class="badge bg-danger">{{ nomination.decision.get_outcome_display }}</span> - {% else %} - <span class="badge bg-warning">Pending</span> - {% endif %} - - </div> - - <div> - <span>Deadline: </span><span>{{ round.voting_deadline|date:"Y-m-d" }}</span> - </div> - </div> - </div> - - </summary> - - <div id="nomination-{{ nomination.id }}-li-contents" - hx-get="{% url 'colleges:_hx_nomination_li_contents' nomination_id=nomination.id %}" - hx-trigger="intersect once"></div> - </details> -</div> diff --git a/scipost_django/colleges/templates/colleges/_hx_nominations_new.html b/scipost_django/colleges/templates/colleges/_hx_nomination_new.html similarity index 100% rename from scipost_django/colleges/templates/colleges/_hx_nominations_new.html rename to scipost_django/colleges/templates/colleges/_hx_nomination_new.html diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_vote.html b/scipost_django/colleges/templates/colleges/_hx_nomination_vote.html index 2ae937660..456572351 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_vote.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_vote.html @@ -2,7 +2,7 @@ {% for vote_option, color in vote_options %} - <form hx-post="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" + <form hx-post="{% url 'colleges:_hx_nomination_vote' round_id=voting_round.id %}" hx-target="#nomination-{{ voting_round.nomination.id }}-vote"> {% csrf_token %} <input type="hidden" name="vote" value="{{ vote_option }}" /> 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 eb99f0166..7556a7f4c 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,17 +3,17 @@ <nav class="nav nav-pills m-2 overflow-scroll"> {% if should_show_new_round_tab_btn %} - <div 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 + {% 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> {% endif %} {% for voting_round in voting_rounds %} - <div type="button" class="me-2 nav-link + <div id="nomination-{{ nomination.id }}-round-{{ voting_round.id }}-tab-btn" type="button" class="me-2 nav-link {% if selected_round and selected_round.id == voting_round.id %}active{% endif %} {% if voting_round.id in inaccessible_round_ids %}disabled opacity-50{% endif %} diff --git a/scipost_django/colleges/templates/colleges/_hx_nominations.html b/scipost_django/colleges/templates/colleges/_hx_nominations.html deleted file mode 100644 index 6ba5b622f..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_nominations.html +++ /dev/null @@ -1,22 +0,0 @@ -{% for nomination in page_obj %} - <li class="p-2 mb-2" id="nomination_{{ nomination.id }}"> - {% include 'colleges/_hx_nomination_li.html' with nomination=nomination %} - </li> -{% empty %} - <li>No Nomination could be found</li> -{% endfor %} -{% if page_obj.has_next %} - <li hx-post="{% url 'colleges:_hx_nominations' %}?page={{ page_obj.next_page_number }}" - hx-include="#search-nominations-form" - hx-trigger="revealed" - hx-swap="afterend" - hx-indicator="#indicator-search-page-{{ page_obj.number }}" - > - <div id="indicator-search-page-{{ page_obj.number }}" class="htmx-indicator p-2"> - <button class="btn btn-warning" type="button" disabled> - <strong>Loading page {{ page_obj.next_page_number }} out of {{ page_obj.paginator.num_pages }}</strong> - <div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div> - </button> - </div> - </li> -{% endif %} diff --git a/scipost_django/colleges/templates/colleges/_hx_nominations_invitations.html b/scipost_django/colleges/templates/colleges/_hx_nominations_invitations.html deleted file mode 100644 index 17a67db0d..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_nominations_invitations.html +++ /dev/null @@ -1,33 +0,0 @@ -{% include 'colleges/_hx_nominations_invitations_tablist.html' with selected=selected %} - -{% for invitation in invitations.all %} - <details id="invitation-{{ invitation.id }}-details" - class="my-2 border border-2"> - <summary class="bg-light p-2">{{ invitation }}</summary> - - <div class="row"> - <div class="col-12 col-md"> - <details class="m-2 mt-3 border"> - <summary class="p-2 bg-light d-block list-triangle">Events</summary> - {% include 'colleges/_nomination_events_table.html' with nomination=invitation.nomination %} - </details> - </div> - <div class="col-12 col-md"> - <details open class="m-2 mt-3 border"> - <summary class="p-2 bg-light d-block list-triangle">Checklist</summary> - {% include 'colleges/_nominations_invitation_checklist.html' with invitation=invitation %} - </details> - </div> - </div> - - <div class="p-2"> - <h4>Update the response to this invitation:</h4> - <div id="invitation-{{ invitation.id }}-update-response" - hx-get="{% url 'colleges:_hx_fellowship_invitation_update_response' invitation_id=invitation.id %}" - hx-trigger="toggle from:#invitation-{{ invitation.id }}-details" - hx-target="this"></div> - </div> - </details> -{% empty %} - <p class="p-2">No invitations of this kind</p> -{% endfor %} diff --git a/scipost_django/colleges/templates/colleges/_hx_nominations_invitations_tablist.html b/scipost_django/colleges/templates/colleges/_hx_nominations_invitations_tablist.html deleted file mode 100644 index fe8cb5243..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_nominations_invitations_tablist.html +++ /dev/null @@ -1,7 +0,0 @@ -<div class="tablist"> - {% for choice in response_choices %} - <a hx-get="{% url 'colleges:_hx_nominations_invitations' %}?response={{ choice.0 }}" - {% if selected == choice.0 %}class="selected"{% endif %} - >{{ choice.1 }}</a> - {% endfor %} -</div> diff --git a/scipost_django/colleges/templates/colleges/_hx_nominations_needing_specialties.html b/scipost_django/colleges/templates/colleges/_hx_nominations_needing_specialties.html deleted file mode 100644 index 228dd433c..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_nominations_needing_specialties.html +++ /dev/null @@ -1,15 +0,0 @@ -{% for nomination in nominations_needing_specialties %} - <details id="nomination-{{ nomination.id }}-specialties" - class="border border-2 my-2"> - <summary class="p-2 bg-light">{{ nomination }}</summary> - <div id="profile-{{ nomination.profile.id }}-specialties" - class="p-2 mt-2" - hx-get="{% url 'profiles:_hx_profile_specialties' profile_id=nomination.profile.id %}" - hx-trigger="toggle from:#nomination-{{ nomination.id }}-specialties"></div> - <button class="btn btn-success text-white m-2 nomination-specialties-done-btn" - hx-get="{% url 'colleges:_hx_nominations_needing_specialties' %}" - hx-target="#nominations_needing_specialties">Done</button> - </details> -{% empty %} - <p>All nomination profiles have at least one specialty.</p> -{% endfor %} diff --git a/scipost_django/colleges/templates/colleges/_hx_nominations_no_round_started.html b/scipost_django/colleges/templates/colleges/_hx_nominations_no_round_started.html deleted file mode 100644 index cf3332cdf..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_nominations_no_round_started.html +++ /dev/null @@ -1,16 +0,0 @@ -{% for nomination in nominations_no_round_started %} - <details id="nomination-{{ nomination.id }}-start-round" - class="border border-2 my-2"> - <summary class="p-2 bg-light">{{ nomination }}</summary> - - <div class="p-2 mt-2"> - <div id="nomination-{{ nomination.id }}-eligible-voters" - hx-get="{% url 'colleges:_hx_nomination_eligible_voters' nomination_id=nomination.id %}" - hx-trigger="toggle from:#nomination-{{ nomination.id }}-start-round"></div> - - </div> - - </details> -{% empty %} - <p>All nominations have had their voting round(s) started.</p> -{% endfor %} diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_round_creation.html b/scipost_django/colleges/templates/colleges/_hx_voting_round_creation.html deleted file mode 100644 index 70f6e2881..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_creation.html +++ /dev/null @@ -1,17 +0,0 @@ -{% load crispy_forms_tags %} - -<div class="row"> - <div class="col-8"> - <h4>Eligible voters</h4> - <div id="nomination-{{ nomination.id }}-round-{{ voting_round.id }}-votes" - hx-get="{% url 'colleges:_hx_nomination_voter_table' round_id=voting_round.id %}" - hx-trigger="intersect once"></div> - </div> - <div class="col-4"> - <h4>Add new voter</h4> - </div> - <div class="col-12"> - <h4>Start round</h4> - {% crispy round_start_form %} - </div> -</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 42f237aba..04e8310ef 100644 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html +++ b/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html @@ -42,14 +42,16 @@ </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 %} <div id="nomination-{{ voting_round.nomination.id }}-vote" - hx-get="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" + hx-get="{% url 'colleges:_hx_nomination_vote' round_id=voting_round.id %}" hx-trigger="intersect once"></div> {% endif %} + {% comment %} If round is closed show results if they exist {% endcomment %} {% else %} <div>{% include "colleges/_voting_results_box.html" with voting_round=voting_round %}</div> @@ -80,10 +82,8 @@ {% if not voting_round.is_closed %} - <div class="col-12"> - <h4>Start round</h4> - {% crispy round_start_form %} - </div> + <div hx-get="{% url 'colleges:_hx_voting_round_start_form' round_id=voting_round.id %}" + hx-trigger="intersect once"></div> {% elif voting_round.is_closed and not voting_round.decision %} diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_round_li_contents.html b/scipost_django/colleges/templates/colleges/_hx_voting_round_li_contents.html deleted file mode 100644 index e72444b39..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_li_contents.html +++ /dev/null @@ -1,19 +0,0 @@ -<div class="row"> - <div class="col"> - - {% if session_fellowship and session_fellowship in round.eligible_to_vote.all or "edadmin" in user_roles %} - - {% if round.is_open and session_fellowship in round.eligible_to_vote.all %} - <div id="nomination-{{ round.nomination.id }}-vote" - hx-get="{% url 'colleges:_hx_nomination_vote' voting_round_id=round.id %}" - hx-trigger="intersect once"></div> - {% else %} - {% include "colleges/_hx_voting_round_results.html" with voting_round=round %} - {% endif %} - - {% else %} - <p>You are not called upon to vote in this round.</p> - {% endif %} - - </div> -</div> diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_round_list.html b/scipost_django/colleges/templates/colleges/_hx_voting_round_list.html deleted file mode 100644 index bfbd6306d..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_list.html +++ /dev/null @@ -1,24 +0,0 @@ -{% for round in page_obj %} - <div class="ms-1 mt-2">{% include 'colleges/_hx_voting_round_details.html' with round=round %}</div> -{% empty %} - <strong>No Voting Rounds could be found</strong> -{% endfor %} - -{% if page_obj.has_next %} - <div hx-post="{% url 'colleges:_hx_nominations_list' %}?page={{ page_obj.next_page_number }}" - hx-include="#search-voting_rounds-form" - hx-trigger="revealed" - hx-swap="afterend" - hx-indicator="#indicator-search-page-{{ page_obj.number }}"> - <div id="indicator-search-page-{{ page_obj.number }}" - class="htmx-indicator p-2"> - <button class="btn btn-warning" type="button" disabled> - <strong>Loading page {{ page_obj.next_page_number }} out of {{ page_obj.paginator.num_pages }}</strong> - - <div class="spinner-grow spinner-grow-sm ms-2" - role="status" - aria-hidden="true"></div> - </button> - </div> - </div> -{% endif %} diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_round_results.html b/scipost_django/colleges/templates/colleges/_hx_voting_round_results.html deleted file mode 100644 index 80c0cda1e..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_results.html +++ /dev/null @@ -1,17 +0,0 @@ -{% if "edadmin" in user_roles %} - <h3>Votes</h3> - <div id="nomination-{{ nomination.id }}-round-{{ voting_round.id }}-votes" - hx-get="{% url 'colleges:_hx_nomination_voter_table' round_id=voting_round.id %}" - hx-trigger="intersect once"></div> -{% endif %} - -<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-12 col-md mt-3">{% include "colleges/_voting_results_box.html" with voting_round=voting_round %}</div> -</div> diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_round_start_form.html b/scipost_django/colleges/templates/colleges/_hx_voting_round_start_form.html new file mode 100644 index 000000000..2fffd05b3 --- /dev/null +++ b/scipost_django/colleges/templates/colleges/_hx_voting_round_start_form.html @@ -0,0 +1,7 @@ +{% load crispy_forms_tags %} + +<form id="voting-round-{{ round.id }}-start-round-form" + hx-post="{% url 'colleges:_hx_voting_round_start_form' round_id=round.id %}" + hx-target="#voting-round-{{ round.id }}-start-round-form"> + {% crispy form %} +</form> diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_rounds.html b/scipost_django/colleges/templates/colleges/_hx_voting_rounds.html deleted file mode 100644 index 710a57c30..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_voting_rounds.html +++ /dev/null @@ -1,11 +0,0 @@ -{% include 'colleges/_hx_voting_rounds_tablist.html' with selected=selected %} - -{% for round in voting_rounds %} - <div id="voting_round_{{ round.id }}"> - - {% include 'colleges/_hx_nomination_li.html' with nomination=round.nomination %} - - </div> -{% empty %} - <div class="p-2">No voting round found</div> -{% endfor %} diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_rounds_tablist.html b/scipost_django/colleges/templates/colleges/_hx_voting_rounds_tablist.html deleted file mode 100644 index 9e584c125..000000000 --- a/scipost_django/colleges/templates/colleges/_hx_voting_rounds_tablist.html +++ /dev/null @@ -1,9 +0,0 @@ -<div class="tablist"> - - {% for tab_choice in tab_choices %} - <a hx-get="{% url 'colleges:_hx_voting_rounds' %}?tab={{ tab_choice.0 }}" hx-target="#voting_tablist" - {% if selected == tab_choice.0 %}class="selected"{% endif %} - >{{ tab_choice.1 }}</a> - {% endfor %} - -</div> diff --git a/scipost_django/colleges/templates/colleges/nominations.html b/scipost_django/colleges/templates/colleges/nominations.html index 0e7fe2e14..388feb729 100644 --- a/scipost_django/colleges/templates/colleges/nominations.html +++ b/scipost_django/colleges/templates/colleges/nominations.html @@ -54,7 +54,7 @@ <button class="btn btn-success me-2 text-white" type="button" - hx-get="{% url 'colleges:_hx_nominations_new' %}" + hx-get="{% url 'colleges:_hx_nomination_new' %}" hx-trigger="click" hx-target="#new-nomination-container"> {% include "bi/plus-square.html" %} diff --git a/scipost_django/colleges/urls.py b/scipost_django/colleges/urls.py index 8bf4c9867..f24fb4520 100644 --- a/scipost_django/colleges/urls.py +++ b/scipost_django/colleges/urls.py @@ -161,86 +161,94 @@ urlpatterns = [ views.PotentialFellowshipListView.as_view(), name="potential_fellowships", ), - # Nominations - path("nominations", views.nominations, name="nominations"), + ########################## + # Nominations and Voting # + ########################## path( - "_hx_nomination_form/<int:profile_id>", - views._hx_nomination_form, - name="_hx_nomination_form", - ), - path("_hx_nominations", views._hx_nominations, name="_hx_nominations"), - path( - "_hx_nominations_search_form/<str:filter_set>", - views._hx_nominations_search_form, - name="_hx_nominations_search_form", - ), - path( - "_hx_nomination_li_contents/<int:nomination_id>", - views._hx_nomination_li_contents, - name="_hx_nomination_li_contents", - ), - path( - "_hx_nomination_voter_table/<int:round_id>", - views._hx_nomination_voter_table, - name="_hx_nomination_voter_table", - ), - path( - "_hx_nomination_comments/<int:nomination_id>", - views._hx_nomination_comments, - name="_hx_nomination_comments", - ), - path( - "_hx_nominations_needing_specialties", - views._hx_nominations_needing_specialties, - name="_hx_nominations_needing_specialties", - ), - path( - "_hx_nominations_no_round_started", - views._hx_nominations_no_round_started, - name="_hx_nominations_no_round_started", - ), - path( - "<int:nomination_id>/", + "nominations/", include( [ + path("", views.nominations, name="nominations"), + path("_hx_new", views._hx_nomination_new, name="_hx_nomination_new"), path( - "_hx_nomination_eligible_voters", - views._hx_nomination_eligible_voters, - name="_hx_nomination_eligible_voters", + "_hx_new_form/<int:profile_id>", + views._hx_nomination_form, + name="_hx_nomination_form", ), path( - "_hx_nomination_round_start", - views._hx_nomination_round_start, - name="_hx_nomination_round_start", - ), - path( - "_hx_nomination_voting_rounds_tab/<int:round_id>", - views._hx_nomination_voting_rounds_tab, - name="_hx_nomination_voting_rounds_tab", + "search", + include( + [ + path( + "_hx_form/<str:filter_set>", + views._hx_nominations_search_form, + name="_hx_nominations_search_form", + ), + path( + "_hx_list", + views._hx_nominations_list, + name="_hx_nominations_list", + ), + ] + ), ), path( - "_hx_nomination_voting_rounds_create", - views._hx_nomination_voting_rounds_create, - name="_hx_nomination_voting_rounds_create", + "<int:nomination_id>/", + include( + [ + path( + "_hx_round_tab/<int:round_id>", + views._hx_nomination_voting_rounds_tab, + name="_hx_nomination_voting_rounds_tab", + ), + path( + "_hx_details_contents", + views._hx_nomination_details_contents, + name="_hx_nomination_details_contents", + ), + path( + "_hx_create_voting_round", + views._hx_nomination_voting_rounds_create, + name="_hx_nomination_voting_rounds_create", + ), + path( + "_hx_comments", + views._hx_nomination_comments, + name="_hx_nomination_comments", + ), + ] + ), ), ] ), ), # Nomination Rounds path( - "<int:round_id>/", + "nomination_voting_round/<int:round_id>/", include( [ - # Display round + path("_hx_vote", views._hx_nomination_vote, name="_hx_nomination_vote"), path( - "details", - views._hx_voting_round_li_contents, - name="_hx_voting_round_li_contents", + "_hx_voter_table", + views._hx_nomination_voter_table, + name="_hx_nomination_voter_table", ), path( - "results", - views._hx_voting_round_results, - name="_hx_voting_round_results", + "forms/", + include( + [ + path( + "start_round", + views._hx_voting_round_start_form, + name="_hx_voting_round_start_form", + ), + path( + "decision", + views._hx_nomination_decision_form, + name="_hx_nomination_decision_form", + ), + ] + ), ), # Manage voters of a nomination round path( @@ -263,36 +271,6 @@ urlpatterns = [ ], ), ), - path( - "_hx_voting_rounds", - views._hx_voting_rounds, - name="_hx_voting_rounds", - ), - path( - "_hx_nominations_list", - views._hx_nominations_list, - name="_hx_nominations_list", - ), - path( - "_hx_nomination_vote/<int:voting_round_id>", - views._hx_nomination_vote, - name="_hx_nomination_vote", - ), - path( - "_hx_nomination_decision_form/<int:round_id>", - views._hx_nomination_decision_form, - name="_hx_nomination_decision_form", - ), - path( - "_hx_nominations_invitations", - views._hx_nominations_invitations, - name="_hx_nominations_invitations", - ), - path( - "_hx_nominations_new", - views._hx_nominations_new, - name="_hx_nominations_new", - ), path( "fellowship_invitation/<int:pk>/email_initial", views.FellowshipInvitationEmailInitialView.as_view(), diff --git a/scipost_django/colleges/views.py b/scipost_django/colleges/views.py index a3ab0c3e2..c4d05db52 100644 --- a/scipost_django/colleges/views.py +++ b/scipost_django/colleges/views.py @@ -726,9 +726,9 @@ def _hx_nomination_form(request, profile_id): by=request.user.contributor, ) event.save() - return HttpResponse( - f'<div class="bg-success text-white p-2 ">{nomination.profile} ' - f"successfully nominated to {nomination.college}.</div>" + return HTMXResponse( + f"{nomination.profile} successfully nominated to {nomination.college}.", + tag="success", ) nomination_form.fields["nominated_by"].initial = request.user.contributor context = { @@ -738,56 +738,6 @@ def _hx_nomination_form(request, profile_id): return render(request, "colleges/_hx_nomination_form.html", context) -@login_required -@user_passes_test(is_edadmin_or_senior_fellow) -def _hx_nominations_needing_specialties(request): - nominations_needing_specialties = FellowshipNomination.objects.filter( - profile__specialties__isnull=True, - ) - context = { - "nominations_needing_specialties": nominations_needing_specialties, - } - return render( - request, - "colleges/_hx_nominations_needing_specialties.html", - context, - ) - - -@login_required -@user_passes_test(is_edadmin_or_senior_fellow) -def _hx_nominations_no_round_started(request): - nominations_no_round_started = FellowshipNomination.objects.exclude( - profile__specialties__isnull=True - ).filter(voting_rounds__isnull=False) - context = { - "nominations_no_round_started": nominations_no_round_started, - } - return render( - request, - "colleges/_hx_nominations_no_round_started.html", - context, - ) - - -@login_required -@user_passes_test(is_edadmin_or_senior_fellow) -def _hx_nomination_eligible_voters(request, nomination_id): - nomination = FellowshipNomination.objects.get(pk=nomination_id) - eligible_voters = nomination.get_eligible_voters - context = { - "nomination": nomination, - "eligible_voters": eligible_voters, - "nominee_specialties": nomination.profile.specialties.all(), - "round": nomination.voting_rounds.first(), - } - return render( - request, - "colleges/_hx_nomination_eligible_voters.html", - context, - ) - - def _hx_nomination_round_remove_voter(request, round_id, voter_id): """Remove a voter from a nomination's voting round.""" round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id) @@ -804,54 +754,15 @@ def _hx_nomination_round_remove_voter(request, round_id, voter_id): return HttpResponse("") -def _hx_nomination_round_start(request, nomination_id): - """Create a voting round for the specified nomination using the default eligible voters.""" - nomination = get_object_or_404(FellowshipNomination, pk=nomination_id) - # Find ongoing round for this nomination, if any - ongoing_round = nomination.voting_rounds.ongoing().first() - if ongoing_round: - return HTMXResponse( - f"Round for {nomination.profile} already ongoing until {ongoing_round.voting_deadline}", - tag="danger", - ) - voting_round = FellowshipNominationVotingRound( - nomination=nomination, - voting_opens=timezone.now(), - voting_deadline=timezone.now() + datetime.timedelta(days=14), - ) - voting_round.save() - voting_round.eligible_to_vote.set(nomination.get_eligible_voters) - voting_round.save() - return HTMXResponse( - f"Started round for {nomination.profile} from now until {voting_round.voting_deadline}.", - tag="success", - ) - - @login_required @user_passes_test(is_edadmin_or_advisory_or_active_regular_or_senior_fellow) -def _hx_nominations(request): - form = FellowshipNominationSearchForm(request.POST or None) - if form.is_valid(): - nominations = form.search_results() - else: - nominations = FellowshipNomination.objects.all() - paginator = Paginator(nominations, 16) - page_nr = request.GET.get("page") - page_obj = paginator.get_page(page_nr) - context = {"page_obj": page_obj} - return render(request, "colleges/_hx_nominations.html", context) - - -@login_required -@user_passes_test(is_edadmin_or_advisory_or_active_regular_or_senior_fellow) -def _hx_nomination_li_contents(request, nomination_id): +def _hx_nomination_details_contents(request, nomination_id): """For (re)loading the details if modified.""" nomination = get_object_or_404(FellowshipNomination, pk=nomination_id) context = { "nomination": nomination, } - return render(request, "colleges/_hx_nomination_li_contents.html", context) + return render(request, "colleges/_hx_nomination_details_contents.html", context) def _hx_nominations_search_form(request, filter_set: str): @@ -890,15 +801,6 @@ def _hx_nominations_list(request): return render(request, "colleges/_hx_nominations_list.html", context) -def _hx_voting_round_results(request, round_id): - """For (re)loading the details if modified.""" - round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id) - context = { - "round": round, - } - return render(request, "colleges/_hx_voting_round_results.html", context) - - @login_required @user_passes_test(is_edadmin_or_advisory_or_active_regular_or_senior_fellow) def _hx_nomination_voting_rounds_tab(request, nomination_id, round_id): @@ -932,11 +834,6 @@ def _hx_nomination_voting_rounds_tab(request, nomination_id, round_id): context["selected_round"] = selected_round 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", @@ -947,15 +844,6 @@ def _hx_nomination_voting_rounds_tab(request, nomination_id, round_id): ) context["voter_add_form"] = voter_add_form - if round_start_form.is_valid(): - round_start_form.save() - messages.success( - request, - f"Voting round for {nomination.profile} started " - f"from {selected_round.voting_opens} until {selected_round.voting_deadline}.", - ) - context["round_start_form"] = round_start_form - return render(request, "colleges/_hx_nomination_voting_rounds_tab.html", context) @@ -972,15 +860,6 @@ def _hx_nomination_voting_rounds_create(request, nomination_id): return _hx_nomination_voting_rounds_tab(request, nomination_id, new_round.id) -def _hx_voting_round_li_contents(request, round_id): - """For (re)loading the details if modified.""" - round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id) - context = { - "round": round, - } - return render(request, "colleges/_hx_voting_round_li_contents.html", context) - - @login_required @user_passes_test(is_edadmin_or_advisory_or_active_regular_or_senior_fellow) def _hx_nomination_comments(request, nomination_id): @@ -1003,61 +882,11 @@ def _hx_nomination_comments(request, nomination_id): @login_required @user_passes_test(is_edadmin_or_advisory_or_active_regular_or_senior_fellow) -def _hx_voting_rounds(request): - selected = request.GET.get("tab", "ongoing") - tab_choices = [] - if request.user.contributor.is_ed_admin: - tab_choices += [ - ("ongoing", "Ongoing"), - ("closed-pending", "Closed"), - ("closed-elected", "Closed (elected)"), - ("closed-notelected", "Closed (not elected)"), - ] - elif request.user.contributor.is_active_fellow: - tab_choices += [ - ("ongoing-vote_required", "Cast your vote (election ongoing)"), - ("ongoing-voted", "Votes you have cast (election ongoing)"), - ("closed-voted", "Votes you have cast (election closed)"), - ] - fellowship = request.user.contributor.session_fellowship(request) - voting_rounds = FellowshipNominationVotingRound.objects.all() - if "ongoing" in selected: - voting_rounds = voting_rounds.ongoing() - if "closed" in selected: - voting_rounds = voting_rounds.closed() - if "-pending" in selected: - voting_rounds = voting_rounds.filter(decision__isnull=True) - if "-elected" in selected: - voting_rounds = voting_rounds.filter( - decision__outcome=FellowshipNominationDecision.OUTCOME_ELECTED - ) - if "-notelected" in selected: - voting_rounds = voting_rounds.filter( - decision__outcome=FellowshipNominationDecision.OUTCOME_NOT_ELECTED - ) - if "vote_required" in selected: - # show all voting rounds to edadmin; for Fellow, filter - if not request.user.contributor.is_ed_admin: - voting_rounds = voting_rounds.filter(eligible_to_vote=fellowship).exclude( - votes__fellow=fellowship - ) - if "-voted" in selected: - voting_rounds = voting_rounds.filter(votes__fellow=fellowship) - context = { - "tab_choices": tab_choices, - "selected": selected, - "voting_rounds": voting_rounds, - } - return render(request, "colleges/_hx_voting_rounds.html", context) - - -@login_required -@user_passes_test(is_edadmin_or_advisory_or_active_regular_or_senior_fellow) -def _hx_nomination_vote(request, voting_round_id): +def _hx_nomination_vote(request, round_id): fellowship = request.user.contributor.session_fellowship(request) voting_round = get_object_or_404( FellowshipNominationVotingRound, - pk=voting_round_id, + pk=round_id, eligible_to_vote=fellowship, ) @@ -1106,6 +935,29 @@ def _hx_nomination_vote(request, voting_round_id): return render(request, "colleges/_hx_nomination_vote.html", context) +@login_required +@user_passes_test(is_edadmin) +def _hx_voting_round_start_form(request, round_id): + round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id) + form = FellowshipNominationVotingRoundStartForm( + request.POST or None, + instance=round, + ) + if form.is_valid(): + form.save() + messages.success( + request, + f"Voting round for {round.nomination.profile} started " + f"from {round.voting_opens} until {round.voting_deadline}.", + ) + + return render( + request, + "colleges/_hx_voting_round_start_form.html", + {"form": form, "round": round}, + ) + + @login_required @user_passes_test(is_edadmin) def _hx_nomination_decision_form(request, round_id): @@ -1134,7 +986,7 @@ def _hx_nomination_decision_form(request, round_id): # Check permission to create a new nomination -def _hx_nominations_new(request): +def _hx_nomination_new(request): """Render the contents of the new nomination form.""" profile_dynsel_form = ProfileDynSelForm( initial={ @@ -1148,23 +1000,7 @@ def _hx_nominations_new(request): "profile_dynsel_form": profile_dynsel_form, } - return render(request, "colleges/_hx_nominations_new.html", context) - - -@login_required -@user_passes_test(is_edadmin) -def _hx_nominations_invitations(request): - selected = request.GET.get("response", "notyetinvited") - invitations = FellowshipInvitation.objects.filter( - nomination__fellowship__isnull=True, - response=selected, - ) - context = { - "response_choices": FellowshipInvitation.RESPONSE_CHOICES, - "selected": selected, - "invitations": invitations, - } - return render(request, "colleges/_hx_nominations_invitations.html", context) + return render(request, "colleges/_hx_nomination_new.html", context) class FellowshipInvitationEmailInitialView(PermissionsMixin, MailView): -- GitLab