Skip to content

Commit 14b39ee

Browse files
committed
list_*() should return EasyDict objects
1 parent dab12c6 commit 14b39ee

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

v3/steve/election.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import pathlib
2727

2828
import asfpy.db
29+
import easydict
2930

3031
from . import crypto
3132
from . import vtypes
@@ -114,11 +115,10 @@ def gather_election_data(self, pdb):
114115
idata = ''.join(f'{i.iid}{i.title}{i.description}{i.type}{i.kv}'
115116
for i in self.q_issues.fetchall())
116117

118+
# Include the PID and EMAIL for each Person.
117119
### we don't want all people. Just those who are allowed to
118120
### vote in this Election. Examine the "mayvote" table.
119-
### list_persons returns 3-tuples of (PID,NAME,EMAIL). We only
120-
### want pid/email in PDATA.
121-
pdata = ''.join(p[0] + p[2] for p in pdb.list_persons())
121+
pdata = ''.join(p.pid + p.email for p in pdb.list_persons())
122122

123123
return (mdata + idata + pdata).encode()
124124

@@ -188,11 +188,15 @@ def delete_issue(self, iid):
188188
self.c_delete_issue.perform(iid)
189189

190190
def list_issues(self):
191-
"Return ordered (IID, TITLE, DESCRIPTION, TYPE, KV) for all ISSUES."
191+
"Return ordered EasyDicgt<IID, TITLE, DESCRIPTION, TYPE, KV> for all ISSUES."
192192

193193
def extract_issue(row):
194-
return (row.iid, row.title, row.description, row.type,
195-
self.json2kv(row.kv),)
194+
return easydict.EasyDict(iid=row.iid,
195+
title=row.title,
196+
description=row.description,
197+
type=row.type,
198+
kv=self.json2kv(row.kv),
199+
)
196200

197201
self.q_issues.perform(self.eid)
198202
return [ extract_issue(row) for row in self.q_issues.fetchall() ]

v3/steve/persondb.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import pathlib
2323

2424
import asfpy.db
25+
import easydict
2526

2627
THIS_DIR = pathlib.Path(__file__).resolve().parent
2728
QUERIES = THIS_DIR.parent / 'queries.yaml'
@@ -63,8 +64,10 @@ def delete_person(self, pid):
6364
self.c_delete_person.perform(pid)
6465

6566
def list_persons(self):
66-
"Return ordered (PID, NAME, EMAIL) for each Person."
67+
"Return ordered EasyDict<PID, NAME, EMAIL> for each Person."
6768

69+
### switch to explicitly returning a generator?
70+
71+
# Run the query to completion, and return the entire list of Persons.
6872
self.q_person.perform()
69-
return [ (row.pid, row.name, row.email)
70-
for row in self.q_person.fetchall() ]
73+
return list(self.q_person.fetchall())

0 commit comments

Comments
 (0)