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 de04ea7  Display issue count and admin count.
de04ea7 is described below

commit de04ea746771ffa79475530562a457bc3b8cedd2
Author: Greg Stein <[email protected]>
AuthorDate: Sun Oct 5 00:25:24 2025 -0500

    Display issue count and admin count.
    
    * queries.yaml: q_open_to_me reture issue_count for each election open
      to the Person.
    * pages.py:voter_page(): remove debug stuff, we now have load_fakedata
      to populate the DB for stuff to work with. minor tweaks and push the
      length of the lists into the template.
    * voter.ezt: include issue count. refer to admin page for those
      elections.
---
 v3/queries.yaml               |  8 +++++---
 v3/server/pages.py            | 47 +++++++++++--------------------------------
 v3/server/templates/voter.ezt |  9 ++-------
 3 files changed, 19 insertions(+), 45 deletions(-)

diff --git a/v3/queries.yaml b/v3/queries.yaml
index b315d33..be93e24 100644
--- a/v3/queries.yaml
+++ b/v3/queries.yaml
@@ -90,15 +90,17 @@ election:
     # Which elections are open for voting by PID?
     # Note: SALT and OPENED_KEY are never returned.
     q_open_to_me: |
-        SELECT DISTINCT e.eid, e.title, e.owner_pid, e.authz, e.closed,
-                        e.open_at, e.close_at,
-                        (e.opened_key IS NOT NULL) AS is_opened
+        SELECT e.eid, e.title, e.owner_pid, e.authz, e.closed,
+               e.open_at, e.close_at,
+               (e.opened_key IS NOT NULL) AS is_opened,
+               COUNT(i.iid) AS issue_count
         FROM mayvote m
         JOIN issue i ON m.iid = i.iid
         JOIN election e ON i.eid = e.eid
         WHERE m.pid = ?
           AND e.salt IS NOT NULL
           AND (e.closed IS NULL OR e.closed = 0)
+        GROUP BY e.eid
         ORDER BY e._ROWID_
 
     # Which elections were created by PID?
diff --git a/v3/server/pages.py b/v3/server/pages.py
index d6f2ca4..3ab5340 100644
--- a/v3/server/pages.py
+++ b/v3/server/pages.py
@@ -72,43 +72,17 @@ async def home_page():
 @asfquart.auth.require({R.committer})  ### need general solution
 @APP.use_template('templates/voter.ezt')
 async def voter_page():
+    pid = 'gstein'  ### get from session
+
     with asfpy.stopwatch.Stopwatch():
         # These are lists of EasyDict instances for each Election.
-        election = steve.election.Election.open_to_pid(DB_FNAME, 'gstein')
-        owned = steve.election.Election.owned_elections(DB_FNAME, 'gstein')
-
-    ### for now
-    def some_future():
-        import random
-
-        # 50% no time
-        if random.randrange(2):
-            return None
-        # 66% days, then: 50% hours or minutes each
-        if random.randrange(3):
-            delta = random.randint(5, 20) * 24 * 60 * 60  # days
-        elif random.randrange(2):
-            delta = random.randint(5, 40) * 60 * 60  # hours
-        else:
-            delta = random.randint(10, 50) * 60  # minutes
-
-        return (datetime.datetime.now() + datetime.timedelta(seconds=delta)
-                ).timestamp()
-
-    def new_test_election():
-        import random
-        return edict(
-            eid=steve.crypto.create_id(),
-            title=f'Title blah:{steve.crypto.create_id()}',
-            owner_pid='alice',
-            authz=None,
-            is_opened=(random.randrange(10) < 3),  # open 30%
-            closed=(random.randrange(10) < 3),  # closed 30%
-            open_at=some_future(),
-            close_at=some_future(),
-            )
-    election = [ new_test_election() for i in range(10) ]
-    owned = [ new_test_election() for i in range(10) ]
+        election = steve.election.Election.open_to_pid(DB_FNAME, pid)
+        owned = steve.election.Election.owned_elections(DB_FNAME, pid)
+
+    ### should change q_owned to return owner_pid even though it is
+    ### known from the query param. (ie. solve in sql, not python)
+    for e in owned:
+        e.owner_pid = pid
 
     result = await signin_info()
     result.title = 'Voting'
@@ -116,6 +90,9 @@ async def voter_page():
     result.election = [ postprocess_election(e) for e in election ]
     result.owned = [ postprocess_election(e) for e in owned ]
 
+    result.len_elections = len(result.election)
+    result.len_owned = len(result.owned)
+
     return result
 
 
diff --git a/v3/server/templates/voter.ezt b/v3/server/templates/voter.ezt
index 20a9a75..544d7fe 100644
--- a/v3/server/templates/voter.ezt
+++ b/v3/server/templates/voter.ezt
@@ -11,7 +11,7 @@
                               ][if-any election.closed] (closed)[else][#
                               ][if-any election.is_opened] 
(open)[end][end]</h5>
                             <p class="card-text">
-                                something about the election?
+                                You have [election.issue_count] issues to vote 
upon.
                                 <br/>
                                 eid: [election.eid]
                                 <br/>
@@ -57,12 +57,7 @@
           [end]
 
         <p>
-          [for owned]
-            [owned.eid] [owned.title] [owned.owner_pid]
-            [owned.authz] [owned.closed]
-            [owned.open_at] [owned.fmt_open_at] [owned.fmt_open_at_full]
-            [owned.close_at] [owned.fmt_close_at] [owned.fmt_close_at_full]
-          [end]
+          You have [len_owned] <a href="/admin">elections to manage</a>.
         </p>
     </div>
 [include "footer.ezt"]

Reply via email to