Skip to content

Commit 572d239

Browse files
feat: add set_open_at and set_close_at methods to Election class
Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) <aider@aider.chat>
1 parent 62facf9 commit 572d239

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

v3/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Based on a review of `v3/server/pages.py` (and related templates like `voter.ezt
55
## 1. Missing Endpoints for Date Saving (Critical) - RESOLVED
66
- **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).
77
- **Impact**: Users won't be able to save dates via the UI, breaking the intended workflow.
8-
- **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.
8+
- **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 in `queries.yaml`.
99

1010
## 2. Upcoming Elections Not Populated in `voter_page()`
1111
- **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.

v3/queries.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ election:
5959
)
6060
c_delete_issues: DELETE FROM issue WHERE eid = ?
6161
c_delete_election: DELETE FROM election WHERE eid = ?
62+
c_set_open_at: UPDATE election SET open_at = ? WHERE eid = ?
63+
c_set_close_at: UPDATE election SET close_at = ? WHERE eid = ?
6264

6365
# Fast check to see if the Election exists. No data returned.
6466
q_check_election: SELECT 1 FROM election WHERE eid = ?

v3/steve/election.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,14 @@ def owned_elections(cls, db_fname, pid):
484484
)
485485
return [row for row in db.q_owned.fetchall()]
486486

487+
def set_open_at(self, timestamp):
488+
"Set the open_at timestamp for this Election."
489+
self.c_set_open_at.perform(timestamp, self.eid)
490+
491+
def set_close_at(self, timestamp):
492+
"Set the close_at timestamp for this Election."
493+
self.c_set_close_at.perform(timestamp, self.eid)
494+
487495

488496
def not_found(cursor, key):
489497
row = cursor.first_row(key)

0 commit comments

Comments
 (0)