From d137862c8a2a2b8965eb1e3c1866abc7a03d53b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1?= <git@imaniti.org>
Date: Fri, 27 Jan 2023 20:59:25 +0100
Subject: [PATCH] further ui work

---
 .../rv_voting_calc/includes/option_list.html  | 32 ++++++++++---------
 .../rv_voting_calc/steps/with_support.html    |  8 +++--
 rv_voting_calc/views.py                       | 12 +++----
 3 files changed, 29 insertions(+), 23 deletions(-)

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
index 914796d..49acdf6 100644
--- a/rv_voting_calc/templates/rv_voting_calc/includes/option_list.html
+++ b/rv_voting_calc/templates/rv_voting_calc/includes/option_list.html
@@ -2,7 +2,7 @@
 
 <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">
+        <h3 class="flex gap-2 items-end text-xl font-semibold">
             {{ option_key }}
             <span class="text-sm text-gray-600">
                 {{ option.ticket_count }} lístků, {{ option.vote_count }} hlasů
@@ -12,19 +12,21 @@
             {% 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>
+        {% if option.votes|length != 0 %}
+            <ul class="flex gap-3 mt-1">
+                {% 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>
+        {% endif %}
     {% endfor %}
 </ul>
diff --git a/rv_voting_calc/templates/rv_voting_calc/steps/with_support.html b/rv_voting_calc/templates/rv_voting_calc/steps/with_support.html
index 44de8e4..c90da9e 100644
--- a/rv_voting_calc/templates/rv_voting_calc/steps/with_support.html
+++ b/rv_voting_calc/templates/rv_voting_calc/steps/with_support.html
@@ -1,3 +1,7 @@
-CIRNO CHIRUMIRU
+<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 vyřazení možností bez nadpoloviční podpory</h2>
+    </div>
 
-{{ options }}
+    {% include "rv_voting_calc/includes/option_list.html" with options=options options_by_member=options_by_member %}
+</li>
diff --git a/rv_voting_calc/views.py b/rv_voting_calc/views.py
index 9329767..752108c 100644
--- a/rv_voting_calc/views.py
+++ b/rv_voting_calc/views.py
@@ -126,8 +126,8 @@ def get_calculated_votes(request):
     total_ticket_count = len(options_by_member)  # 1 member = 1 ticket
     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:
+    # If the ticket count is divisible by 2, add 1 to make the treshold >half
+    if total_ticket_count % 2 == 0:
         has_support_treshold += 1
 
     max_vote_position = 0
@@ -168,10 +168,7 @@ def get_calculated_votes(request):
     options_to_remove = []
 
     for option_key, option in options.items():
-        if (
-            (option["vote_count"] + option["ticket_count"])
-            >= has_support_treshold
-        ):
+        if option["vote_count"] >= has_support_treshold:
             option["has_support"] = True
 
         if not option["has_support"]:
@@ -207,6 +204,9 @@ 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