You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by hu...@apache.org on 2015/03/27 12:03:14 UTC

svn commit: r1669539 - /steve/trunk/pysteve/lib/election.py

Author: humbedooh
Date: Fri Mar 27 11:03:13 2015
New Revision: 1669539

URL: http://svn.apache.org/r1669539
Log:
- Allow votes to carry metadata
- Add backwards compat for old vote data without metadata
- Add method for getting raw vote data (including metadata)

Modified:
    steve/trunk/pysteve/lib/election.py

Modified: steve/trunk/pysteve/lib/election.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/election.py?rev=1669539&r1=1669538&r2=1669539&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/election.py (original)
+++ steve/trunk/pysteve/lib/election.py Fri Mar 27 11:03:13 2015
@@ -174,7 +174,10 @@ def vote(electionID, issueID, voterID, v
                 with open(issuepath + ".votes", "r") as f:
                     votes = json.loads(f.read())
                     f.close()
-            votes[voterID] = vote
+            votes[voterID] = {
+                'vote': vote,
+                'timestamp': time.time()
+            }
             with open(issuepath + ".votes", "w") as f:
                 f.write(json.dumps(votes))
                 f.close()
@@ -200,6 +203,25 @@ def getVotes(electionID, issueID):
     if config.get("database", "dbsys") == "file":
         issuepath = os.path.join(homedir, "issues", electionID, issueID) + ".json.votes"
         if os.path.isfile(issuepath):
+            votes = {}
+            rvotes = {}
+            with open(issuepath, "r") as f:
+                rvotes = json.loads(f.read())
+                f.close()
+            for key in rvotes:
+                if isinstance(rvotes[key], dict):
+                    votes[key] = rvotes[key]['vote']
+                elif isinstance(rvotes[key], str) or isinstance(rvotes[key], unicode):
+                    votes[key] =rvotes[key]
+                else:
+                    raise Exception("Invalid vote data found: %s" % type(rvotes[key]))
+            return votes
+    return {}
+
+def getVotesRaw(electionID, issueID):
+    if config.get("database", "dbsys") == "file":
+        issuepath = os.path.join(homedir, "issues", electionID, issueID) + ".json.votes"
+        if os.path.isfile(issuepath):
             with open(issuepath, "r") as f:
                 votes = json.loads(f.read())
                 f.close()