From 6f693f44dcf90a1160f9f271b2b101754dc42499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1?= <git@imaniti.org> Date: Fri, 27 Jan 2023 11:00:43 +0100 Subject: [PATCH] show votes, tickets, whether or not option has support --- .../rv_voting_calc/includes/option_list.html | 30 +++++++++++++++++++ .../templates/rv_voting_calc/index.html | 2 +- .../rv_voting_calc/steps/initial_sort.html | 19 +----------- rv_voting_calc/views.py | 14 +++++---- 4 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 rv_voting_calc/templates/rv_voting_calc/includes/option_list.html diff --git a/rv_voting_calc/templates/rv_voting_calc/includes/option_list.html b/rv_voting_calc/templates/rv_voting_calc/includes/option_list.html new file mode 100644 index 0000000..914796d --- /dev/null +++ b/rv_voting_calc/templates/rv_voting_calc/includes/option_list.html @@ -0,0 +1,30 @@ +{% load index %} + +<ul class="flex flex-col gap-2"> + {% for option_key, option in options.items %} + <h3 class="flex gap-2 items-end text-xl font-semibold mb-1"> + {{ option_key }} + <span class="text-sm text-gray-600"> + {{ option.ticket_count }} lístků, {{ option.vote_count }} hlasů + </span> + {% if show_has_support and not option.has_support %} + <span class="text-sm text-red-600">(Nemá nadpoloviční podporu)</span> + {% endif %} + </h3> + + <ul class="flex gap-3"> + {% for vote in option.votes %} + <li class="flex"> + <div class="px-4 py-2 bg-gray-300"> + {{ vote.member }} + </div> + <ul class="px-4 py-2 flex gap-1 bg-gray-200"> + {% for option in options_by_member|index:vote.member %} + <li>{{ option }}{% if not forloop.last %}, {% endif %}</li> + {% endfor %} + </ul> + </li> + {% endfor %} + </ul> + {% endfor %} +</ul> diff --git a/rv_voting_calc/templates/rv_voting_calc/index.html b/rv_voting_calc/templates/rv_voting_calc/index.html index 6e9ea05..7ae060f 100644 --- a/rv_voting_calc/templates/rv_voting_calc/index.html +++ b/rv_voting_calc/templates/rv_voting_calc/index.html @@ -44,7 +44,7 @@ </ul> <ul - class="flex flex-col gap-3" + class="flex flex-col gap-5" id="result" > diff --git a/rv_voting_calc/templates/rv_voting_calc/steps/initial_sort.html b/rv_voting_calc/templates/rv_voting_calc/steps/initial_sort.html index b9353e8..e93bb2c 100644 --- a/rv_voting_calc/templates/rv_voting_calc/steps/initial_sort.html +++ b/rv_voting_calc/templates/rv_voting_calc/steps/initial_sort.html @@ -1,5 +1,3 @@ -{% load index %} - <li class="bg-gray-100 drop-shadow-md p-4"> <div class="pb-2 mb-2 border-b border-gray-300"> <h2 class="text-2xl font-semibold font-bebas">Počáteční rozdělení</h2> @@ -9,20 +7,5 @@ </small> </div> - {% for option_key, option in options.items %} - <h3 class="text-xl font-semibold">{{ option_key }}</h3> - - <ul class="flex gap-2"> - {% for vote in option.votes %} - <li class="bg-gray-200 px-3 py-2"> - {{ vote.member }} - <ul class="flex gap-1"> - {% for option in options_by_member|index:vote.member %} - <li>{{ option }}{% if not forloop.last %}, {% endif %}</li> - {% endfor %} - </ul> - </li> - {% endfor %} - </ul> - {% endfor %} + {% include "rv_voting_calc/includes/option_list.html" with options=options options_by_member=options_by_member show_has_support=True %} </li> diff --git a/rv_voting_calc/views.py b/rv_voting_calc/views.py index d17426a..9329767 100644 --- a/rv_voting_calc/views.py +++ b/rv_voting_calc/views.py @@ -124,7 +124,12 @@ def get_calculated_votes(request): options = {} total_ticket_count = len(options_by_member) # 1 member = 1 ticket - has_support_treshold = math.ceil(total_ticket_count * 0.5) + 1 + has_support_treshold = math.ceil(total_ticket_count * 0.5) + + # If the number is divisible by 2, add 1 to make it the >half tresold + if has_support_treshold % 2 == 0: + has_support_treshold += 1 + max_vote_position = 0 for member, selected_options in options_by_member.items(): @@ -150,8 +155,8 @@ def get_calculated_votes(request): if option_is_ticket: options[option]["ticket_count"] += 1 - else: - options[option]["vote_count"] += 1 + + options[option]["vote_count"] += 1 option_is_ticket = False @@ -202,9 +207,6 @@ def get_calculated_votes(request): for other_acceptable_option_position, other_acceptable_option in ( enumerate(options_by_member[vote["member"]]) ): - if not options[other_acceptable_option]["has_support"]: - continue - if ( other_acceptable_option_position >= vote["position"] and option["has_support"] -- GitLab