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


The following commit(s) were added to refs/heads/trunk by this push:
     new 572d239  feat: add set_open_at and set_close_at methods to Election 
class
572d239 is described below

commit 572d2393463a4465d65fc9c470f1584ecb8a79b4
Author: Greg Stein <[email protected]>
AuthorDate: Fri Feb 20 01:31:44 2026 -0600

    feat: add set_open_at and set_close_at methods to Election class
    
    Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) <[email protected]>
---
 v3/TODO.md           | 2 +-
 v3/queries.yaml      | 2 ++
 v3/steve/election.py | 8 ++++++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/v3/TODO.md b/v3/TODO.md
index 166611f..d062c76 100644
--- a/v3/TODO.md
+++ b/v3/TODO.md
@@ -5,7 +5,7 @@ Based on a review of `v3/server/pages.py` (and related 
templates like `voter.ezt
 ## 1. Missing Endpoints for Date Saving (Critical) - RESOLVED
 - **Issue**: The `manage.ezt` template includes JavaScript that makes POST 
requests to `/do-set-open_at/<eid>` and `/do-set-close_at/<eid>` for 
auto-saving open/close dates. These endpoints were not defined in `pages.py`, 
causing the auto-save functionality to fail (likely with 404 errors).
 - **Impact**: Users won't be able to save dates via the UI, breaking the 
intended workflow.
-- **Resolution**: Added the two endpoints with a refactored helper function 
`_set_election_date` to handle common logic (auth, JSON parsing, validation, 
setting dates, logging, and response). Endpoints now require authentication, 
validate dates, and log actions. CSRF handling remains a TODO (placeholder 
token in use). Test for proper date-setting and error handling.
+- **Resolution**: Added the two endpoints with a refactored helper function 
`_set_election_date` to handle common logic (auth, JSON parsing, validation, 
setting dates, logging, and response). Endpoints now require authentication, 
validate dates, and log actions. CSRF handling remains a TODO (placeholder 
token in use). Test for proper date-setting and error handling. Added 
supporting methods `set_open_at` and `set_close_at` to the Election class in 
`election.py`, and corresponding cursors [...]
 
 ## 2. Upcoming Elections Not Populated in `voter_page()`
 - **Issue**: The `voter.ezt` template checks for `[if-any upcoming]` and loops 
over `upcoming` elections, but `voter_page()` only sets `result.election` (for 
open elections). `result.upcoming` is never defined, so the "Upcoming 
Elections" section will always be empty.
diff --git a/v3/queries.yaml b/v3/queries.yaml
index e736f0d..363356e 100644
--- a/v3/queries.yaml
+++ b/v3/queries.yaml
@@ -59,6 +59,8 @@ election:
             )
     c_delete_issues: DELETE FROM issue WHERE eid = ?
     c_delete_election: DELETE FROM election WHERE eid = ?
+    c_set_open_at: UPDATE election SET open_at = ? WHERE eid = ?
+    c_set_close_at: UPDATE election SET close_at = ? WHERE eid = ?
 
     # Fast check to see if the Election exists. No data returned.
     q_check_election: SELECT 1 FROM election WHERE eid = ?
diff --git a/v3/steve/election.py b/v3/steve/election.py
index 06b3c04..0b06f35 100644
--- a/v3/steve/election.py
+++ b/v3/steve/election.py
@@ -484,6 +484,14 @@ class Election:
         )
         return [row for row in db.q_owned.fetchall()]
 
+    def set_open_at(self, timestamp):
+        "Set the open_at timestamp for this Election."
+        self.c_set_open_at.perform(timestamp, self.eid)
+
+    def set_close_at(self, timestamp):
+        "Set the close_at timestamp for this Election."
+        self.c_set_close_at.perform(timestamp, self.eid)
+
 
 def not_found(cursor, key):
     row = cursor.first_row(key)

Reply via email to