You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by gs...@apache.org on 2025/12/24 02:22:35 UTC

(steve) branch trunk updated (3f0a114 -> ff8981d)

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

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


    from 3f0a114  hide/revise elements based on the Election state
     new 9063bbe  add little comment about side effects
     new 956e0d8  lean into EasyDict for Election.get_metadata()
     new ff8981d  Expand election data for EZT rendering.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 v3/server/pages.py   | 38 ++++++++++++++++++++++++++------------
 v3/steve/election.py | 16 +++++++++++++---
 2 files changed, 39 insertions(+), 15 deletions(-)


(steve) 01/03: add little comment about side effects

Posted by gs...@apache.org.
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 9063bbe7c118d56ea7e973a9300cd8386be9d48c
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Mon Dec 22 23:39:26 2025 -0600

    add little comment about side effects
---
 v3/server/pages.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/v3/server/pages.py b/v3/server/pages.py
index cb81293..ec6da33 100644
--- a/v3/server/pages.py
+++ b/v3/server/pages.py
@@ -513,6 +513,7 @@ def format_datetime(dt):
 
 def postprocess_election(e):
     "Post-process attributes in an Election, as an EasyDict."
+    # NOTE: side effects. This function manipulates the E argument.
 
     # Anything but 1 means the Election is not closed.
     e.closed = ezt.boolean(e.closed == 1)


(steve) 02/03: lean into EasyDict for Election.get_metadata()

Posted by gs...@apache.org.
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 956e0d87f7b2008b3e671c197b8e80a89386fabc
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Mon Dec 22 23:53:30 2025 -0600

    lean into EasyDict for Election.get_metadata()
---
 v3/server/pages.py   | 20 ++++++++++----------
 v3/steve/election.py | 16 +++++++++++++---
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/v3/server/pages.py b/v3/server/pages.py
index ec6da33..4e60a0d 100644
--- a/v3/server/pages.py
+++ b/v3/server/pages.py
@@ -205,8 +205,8 @@ async def vote_on_page(election):
     result.title = 'Vote On Election'
     result.eid = election.eid
 
-    md = election.get_metadata()
-    result.e_title = md[1]
+    result.election = election.get_metadata()
+    result.e_title = result.election.title
 
     result.issues = election.list_issues()
     result.issue_count = len(result.issues)
@@ -266,9 +266,9 @@ async def manage_page(election):
     result.title = 'Manage an Election'
     result.eid = election.eid
 
-    md = election.get_metadata()
-    result.e_title = md[1]
-    result.e_state = md[2]
+    result.election = election.get_metadata()
+    result.e_title = result.election.title
+    result.e_state = result.election.state
 
     result.issues = election.list_issues()
     result.issue_count = len(result.issues)
@@ -291,9 +291,9 @@ async def manage_stv_page(election, issue):
     result.eid = election.eid
     result.issue = issue
 
-    md = election.get_metadata()
-    result.e_title = md[1]
-    result.e_state = md[2]
+    result.election = election.get_metadata()
+    result.e_title = result.election.title
+    result.e_state = result.election.state
 
     kv = edict(issue.kv)
     result.seats = kv.seats
@@ -342,7 +342,7 @@ async def do_open_endpoint(election):
 
     _LOGGER.info(f'User[U:{result.uid}] opened election[E:{election.eid}]')
 
-    _, title, _ = election.get_metadata()
+    title = election.get_metadata().title
     await flash_success(f'Opened election: {title}')
 
     # Return to the management page for this Election.
@@ -362,7 +362,7 @@ async def do_close_endpoint(election):
 
     _LOGGER.info(f'User[U:{result.uid}] closed election[E:{election.eid}]')
 
-    _, title, _ = election.get_metadata()
+    title = election.get_metadata().title
     await flash_success(f'Closed election: {title}')
 
     # Return to the management page for this Election.
diff --git a/v3/steve/election.py b/v3/steve/election.py
index 2229bad..2311aa5 100644
--- a/v3/steve/election.py
+++ b/v3/steve/election.py
@@ -21,7 +21,7 @@ import sqlite3
 import pathlib
 
 import asfpy.db
-import easydict
+from easydict import EasyDict as edict
 
 from . import crypto
 from . import vtypes
@@ -188,7 +188,17 @@ class Election:
         md = self._all_metadata()
         # NOTE: do not return the SALT or OPENED_KEY
 
-        return md.eid, md.title, self._compute_state(md)
+        return edict(
+            eid=md.eid,
+            title=md.title,
+            owner_pid=md.owner_pid,
+            authz=md.authz,
+            closed=md.closed,  ### should we process this?
+            open_at=md.open_at,  ### should we process this?
+            close_at=md.close_at,  ### should we process this?
+
+            state=self._compute_state(md),
+        )
 
     def get_issue(self, iid):
         "Return TITLE, DESCRIPTION, TYPE, and KV for issue IID."
@@ -252,7 +262,7 @@ class Election:
         "Return ordered EasyDicgt<IID, TITLE, DESCRIPTION, TYPE, KV> for all ISSUES."
 
         def extract_issue(row):
-            return easydict.EasyDict(
+            return edict(
                 iid=row.iid,
                 title=row.title,
                 description=row.description,


(steve) 03/03: Expand election data for EZT rendering.

Posted by gs...@apache.org.
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 ff8981d00648ecf9c566ccc2e0f4b7deb6fc09c1
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Tue Dec 23 20:20:19 2025 -0600

    Expand election data for EZT rendering.
    
    Use postprocess_election() everywhere we have an edict of Election
    data. The dicts are a little bit different based on their origination
    of SELECT vs .get_metadata().
---
 v3/server/pages.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/v3/server/pages.py b/v3/server/pages.py
index 4e60a0d..55d98c5 100644
--- a/v3/server/pages.py
+++ b/v3/server/pages.py
@@ -208,6 +208,9 @@ async def vote_on_page(election):
     result.election = election.get_metadata()
     result.e_title = result.election.title
 
+    # Add more stuff into the Election instance.
+    _ = postprocess_election(result.election)
+
     result.issues = election.list_issues()
     result.issue_count = len(result.issues)
 
@@ -270,6 +273,9 @@ async def manage_page(election):
     result.e_title = result.election.title
     result.e_state = result.election.state
 
+    # Add more stuff into the Election instance.
+    _ = postprocess_election(result.election)
+
     result.issues = election.list_issues()
     result.issue_count = len(result.issues)
 
@@ -295,6 +301,9 @@ async def manage_stv_page(election, issue):
     result.e_title = result.election.title
     result.e_state = result.election.state
 
+    # Add more stuff into the Election instance.
+    _ = postprocess_election(result.election)
+
     kv = edict(issue.kv)
     result.seats = kv.seats
 
@@ -518,8 +527,12 @@ def postprocess_election(e):
     # Anything but 1 means the Election is not closed.
     e.closed = ezt.boolean(e.closed == 1)
 
-    # Anything but 1 means the Election is not open.
-    e.is_opened = ezt.boolean(e.is_opened == 1)
+    # Anything but 1 means the Election has not been opened.
+    if 'is_opened' in e:
+        e.is_opened = ezt.boolean(e.is_opened == 1)
+    else:
+        # Sometimes, we get IS_OPENED. Other times, STATE.
+        e.is_opened = ezt.boolean(e.state != steve.election.Election.S_EDITABLE)
 
     # note: an election has a third Edit state: not open, not closed;
     # this is called "editable" (S_EDITABLE)