This is an automated email from the ASF dual-hosted git repository.

gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit 12b8a9c30fc2ba9ad24c01e9f6fb61da72fb0817
Author: Greg Stein <[email protected]>
AuthorDate: Sat Feb 21 20:23:44 2026 -0600

    feat: make labelmap an easydict and add sorted candidates to STV issues
    
    Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) <[email protected]>
---
 v3/server/pages.py | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/v3/server/pages.py b/v3/server/pages.py
index 151b7c4..a86338e 100644
--- a/v3/server/pages.py
+++ b/v3/server/pages.py
@@ -11,7 +11,7 @@
 # Unless required by applicable law or agreed to in writing,
 # software distributed under the License is distributed on an
 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
+# KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
 
@@ -267,24 +267,33 @@ async def vote_on_page(election):
     # Add more stuff into the Election instance.
     _ = postprocess_election(result.election)
 
-    result.issues = election.list_issues()
-    # Sort issues: STV first, then by title
-    result.issues.sort(key=lambda i: (0 if i.vtype == 'stv' else 1, i.title))
-    result.issue_count = len(result.issues)
+    all_issues = election.list_issues()
+
+    # Split into YNA and STV issues, sort each by title
+    issues_yna = [i for i in all_issues if i.vtype == 'yna']
+    issues_yna.sort(key=lambda i: i.title)
+    issues_stv = [i for i in all_issues if i.vtype == 'stv']
+    issues_stv.sort(key=lambda i: i.title)
 
-    # Add seats for STV issues
-    for issue in result.issues:
-        if issue.vtype == 'stv':
-            issue.seats = issue.kv.get('seats', 0)
+    # Add seats, labelmap, and candidates to STV issues from KV
+    for issue in issues_stv:
+        issue.seats = issue.kv.get('seats', 0)
+        issue.labelmap = edict(issue.kv.get('labelmap', {}))
+        issue.candidates = [{'label': k, 'name': v} for k, v in 
issue.labelmap.items()]
+        issue.candidates.sort(key=lambda c: c['name'])  # Sort candidates by 
name for consistency
 
-    # Scan issues for types and counts
-    yna_count = sum(1 for i in result.issues if i.vtype == 'yna')
-    stv_count = sum(1 for i in result.issues if i.vtype == 'stv')
+    # Compute counts and plurals
+    yna_count = len(issues_yna)
+    stv_count = len(issues_stv)
     result.has_yna_issues = ezt.boolean(yna_count > 0)
     result.has_stv_issues = ezt.boolean(stv_count > 0)
     result.are_yna_plural = ezt.boolean(yna_count > 1)
     result.are_stv_plural = ezt.boolean(stv_count > 1)
 
+    # Combine: STV first, then YNA
+    result.issues = issues_stv + issues_yna
+    result.issue_count = len(result.issues)
+
     result.has_voted = None  # Leave as None for now
 
     return result

Reply via email to