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 6193198511c448e8a343ddb84670dd427e4c1246..dc9e785642ddb1d8a0f633aac0a4085ad8f8edc2 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html @@ -16,12 +16,12 @@ </div> - {% comment %} {% if voting_round.decision.comments %} {% endcomment %} - <div class="col"> - <h4>Decision comments</h4> - <p>{{ voting_round.decision.comments }}</p> - </div> - {% comment %} {% endif %} {% endcomment %} + {% if voting_round.decision.comments %} + <div class="col"> + <h4>Decision comments</h4> + <p>{{ voting_round.decision.comments }}</p> + </div> + {% endif %} </div> diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_vote.html b/scipost_django/colleges/templates/colleges/_hx_nomination_vote.html index 26355ad54f5dd82c6e2549fe697f8639537879a0..9cb3d1f68e39c8eb9b28a2230fd694779842d662 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_vote.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_vote.html @@ -2,46 +2,24 @@ <div class="col-12 col-md"> <h3>Cast your vote:</h3> - {% if vote_object %} - <p>You have previously voted: {{ vote_object.get_vote_display }}.</p> - {% else %} - <p>You have not yet voted on this Nomination.</p> - {% endif %} + {% for vote_option, color in vote_options %} + + <form hx-post="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" + hx-target="#nomination-{{ voting_round.nomination.id }}-vote"> + {% csrf_token %} + <input type="hidden" name="vote" value="{{ vote_option }}" /> + <button class="btn d-flex justify-content-between align-items-center w-100 mb-2 bg-{{ color }} text-white"> + <div>{{ vote_option|title }}</div> + + {% if vote_object.vote == vote_option %} + {% include 'bi/check-square-fill.html' %} + {% endif %} + + </button> + </form> + + {% endfor %} + - <ul class="list-inline m-2"> - <li class="list-inline-item"> - <form hx-post="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" - hx-target="#nomination-{{ voting_round.nomination.id }}-vote"> - {% csrf_token %} - <input type="hidden" name="vote" value="agree" /> - <button class="btn btn-sm btn-success text-white">Agree</button> - </form> - </li> - <li class="list-inline-item"> - <form hx-post="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" - hx-target="#nomination-{{ voting_round.nomination.id }}-vote"> - {% csrf_token %} - <input type="hidden" name="vote" value="abstain" /> - <button class="btn btn-sm btn-warning text-white">Abstain</button> - </form> - </li> - <li class="list-inline-item"> - <form hx-post="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" - hx-target="#nomination-{{ voting_round.nomination.id }}-vote"> - {% csrf_token %} - <input type="hidden" name="vote" value="disagree" /> - <button class="btn btn-sm btn-danger text-white">Disagree</button> - </form> - </li> - <li class="list-inline-item"> - <form hx-post="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" - hx-target="#nomination-{{ voting_round.nomination.id }}-vote"> - {% csrf_token %} - <input type="hidden" name="vote" value="veto" /> - <button class="btn btn-sm btn-dark text-white">Veto</button> - </form> - </li> - </ul> </div> - <div class="col-12 col-md">{% include "colleges/_voting_results_box.html" with voting_round=voting_round %}</div> </div> 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 b56ba572e4982a534ca5d93d9ad168a9a71c6c80..f14bba5b35efd1b39d979981ec73b59d594e41d8 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_voter_table.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_voter_table.html @@ -5,12 +5,16 @@ <th>Fellow</th> <th>Specialties</th> - {% if not round.is_unscheduled %} - <th>Vote</th> - <th>Voted on</th> + {% if "edadmin" in user_roles %} + + {% if not round.is_unscheduled %} + <th>Vote</th> + <th>Voted on</th> + {% endif %} + + <th>Actions</th> {% endif %} - <th>Actions</th> </tr> </thead> @@ -33,36 +37,40 @@ </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> + {% if "edadmin" in user_roles %} + + {% 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>{{ voter.vote.on }}</td> - {% endif %} + <td> - <td> + {% if not round.is_closed %} + <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 %} - {% if not round.is_closed %} - <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> + {% endif %} - </td> </tr> {% endfor %} 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 6a88f8e412bf0df28042b0a2c250b196bb4528b8..4e5f8503f84d3fadce8832139fdf56a9c804b4ee 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 @@ -1,38 +1,47 @@ <div id="nomination-{{ nomination_id }}-round-tab-holder"> <nav class="nav nav-pills m-2 overflow-scroll"> + {% if "edadmin" in user_roles %} - <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> + <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> {% endif %} {% for voting_round in voting_rounds %} - <div 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 %}" - hx-get="{% url 'colleges:_hx_nomination_voting_rounds_tab' nomination_id=nomination_id round_id=voting_round.id %}" - hx-target="#nomination-{{ nomination_id }}-round-tab-holder" - hx-swap="outerHTML"> - <span class="d-block text-nowrap"> - {% if voting_round.voting_opens and voting_round.voting_deadline %} - <small>{{ voting_round.voting_opens|date:"d M Y" }} - {{ voting_round.voting_deadline|date:"d M Y" }}</small> - {% else %} - <span class="badge bg-warning">Unscheduled</span> + <div 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 %} + " hx-get="{% url 'colleges:_hx_nomination_voting_rounds_tab' nomination_id=nomination_id round_id=voting_round.id %}" hx-target="#nomination-{{ nomination_id }}-round-tab-holder" hx-swap="outerHTML"> + <span class="d-block text-nowrap"> + + {% if voting_round.voting_opens and voting_round.voting_deadline %} + <small>{{ voting_round.voting_opens|date:"d M Y" }} - {{ voting_round.voting_deadline|date:"d M Y" }}</small> + {% else %} + <span class="badge bg-warning">Unscheduled</span> + {% endif %} + + <span class="d-flex justify-content-between align-items-center"> + <span>Round #{{ forloop.revcounter }}</span> + + {% if voting_round.is_scheduled %} + <span class="badge bg-primary">Scheduled</span> + {% elif voting_round.is_open %} + <span class="badge bg-success">Open</span> {% endif %} - <span class="d-flex justify-content-between align-items-center"> - <span>Round #{{ forloop.revcounter }}</span> - {% if voting_round.is_scheduled %} - <span class="badge bg-primary">Scheduled</span> - {% elif voting_round.is_open %} - <span class="badge bg-success">Open</span> - {% endif %} - </span> + </span> + </span> </div> {% endfor %} + + <div id="indicator-nomination-{{ nomination_id }}-details-contents" class="htmx-indicator p-2 ms-auto"> <button class="btn btn-warning" type="button" disabled> @@ -47,7 +56,8 @@ </nav> {% if selected_round %} - <div id="nomination-{{ nomination_id }}-round-{{ selected_round.id }}-tab-content-holder" class="mt-3 px-3"> + <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> {% 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 53e52c987c74219ebd0129ea9a503cd4f8d3648b..1c803bd2e6ce851de8aaccf9fafe82aa74265fa5 100644 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html +++ b/scipost_django/colleges/templates/colleges/_hx_voting_round_details.html @@ -1,7 +1,7 @@ {% load crispy_forms_tags %} -<div class="row"> - <div class="col"> +<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 %}" @@ -33,21 +33,57 @@ ALL seniors </button> </div> + + {% elif session_fellowship and session_fellowship in voting_round.eligible_to_vote.all %} + + {% if voting_round.is_open %} + <div id="nomination-{{ voting_round.nomination.id }}-vote" + class="col-12 col-md-4" + hx-get="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" + hx-trigger="intersect once"></div> + {% elif voting_round.decision %} + <div class="col-12 col-md-4 d-flex flex-column justify-content-between"> + <div>{% include "colleges/_voting_results_box.html" with voting_round=voting_round %}</div> + + <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> + {% endif %} + + {% if voting_round.decision.comments %} + <h4 class="mt-2">Decision comments</h4> + <span>{{ voting_round.decision.comments }}</span> + {% endif %} + + </div> + + </div> + + {% endif %} + {% endif %} </div> -{% if voting_round.is_closed %} - <div class="row mb-0"> - <div class="col-12 col-md mt-3"> - <div hx-get="{% url 'colleges:_hx_nomination_decision_form' round_id=voting_round.id %}" - hx-trigger="intersect once"></div> +{% if "edadmin" in user_roles %} + + {% if voting_round.is_closed %} + <div class="row mb-0"> + <div class="col-12 col-md mt-3"> + <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> - <div class="col-auto mt-3">{% include "colleges/_voting_results_box.html" with voting_round=voting_round %}</div> - </div> -{% elif "edadmin" in user_roles %} - <div class="col-12"> - <h4>Start round</h4> - {% crispy round_start_form %} - </div> + {% else %} + <div class="col-12"> + <h4>Start round</h4> + {% crispy round_start_form %} + </div> + {% endif %} + {% endif %} diff --git a/scipost_django/colleges/views.py b/scipost_django/colleges/views.py index df7022cfa6711b8f8b3f64bed5eb8eb70cd6105c..9c0277f94c9dd9bb257eb4da8cdac87cbd908a5b 100644 --- a/scipost_django/colleges/views.py +++ b/scipost_django/colleges/views.py @@ -1050,6 +1050,12 @@ def _hx_nomination_vote(request, voting_round_id): pk=voting_round_id, eligible_to_vote=fellowship, ) + vote_options_with_color = [ + (FellowshipNominationVote.VOTE_AGREE, "success"), + (FellowshipNominationVote.VOTE_ABSTAIN, "warning"), + (FellowshipNominationVote.VOTE_DISAGREE, "danger"), + (FellowshipNominationVote.VOTE_VETO, "dark"), + ] if request.method == "POST": vote_object, created = FellowshipNominationVote.objects.update_or_create( voting_round=voting_round, @@ -1077,6 +1083,7 @@ def _hx_nomination_vote(request, voting_round_id): context = { "voting_round": voting_round, "vote_object": vote_object, + "vote_options": vote_options_with_color, } return render(request, "colleges/_hx_nomination_vote.html", context) @@ -1252,7 +1259,7 @@ def _hx_fellowship_invitation_update_response(request, invitation_id): @login_required -@user_passes_test(is_edadmin) +@user_passes_test(is_edadmin_or_senior_fellow) def _hx_nomination_voter_table(request, round_id): round = get_object_or_404(FellowshipNominationVotingRound, pk=round_id) voters = round.eligible_to_vote.all()