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 2016/02/07 09:56:39 UTC

svn commit: r1728928 - in /steve/trunk/pysteve/lib/backends: es.py files.py

Author: humbedooh
Date: Sun Feb  7 08:56:39 2016
New Revision: 1728928

URL: http://svn.apache.org/viewvc?rev=1728928&view=rev
Log:
func for retrieving history

Modified:
    steve/trunk/pysteve/lib/backends/es.py
    steve/trunk/pysteve/lib/backends/files.py

Modified: steve/trunk/pysteve/lib/backends/es.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/backends/es.py?rev=1728928&r1=1728927&r2=1728928&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/backends/es.py (original)
+++ steve/trunk/pysteve/lib/backends/es.py Sun Feb  7 08:56:39 2016
@@ -103,7 +103,7 @@ class ElasticSearchBackend:
     
     
     def votes_get_raw(self, electionID, issueID):
-        "Read votes and retunn raw format"
+        "Read votes and return raw format"
         res = self.es.search(index="steve", doc_type="votes", q = "election:%s AND issue:%s" % (electionID, issueID), size = 9999)
         results = len(res['hits']['hits'])
         if results > 0:
@@ -113,6 +113,16 @@ class ElasticSearchBackend:
             return votes
         return {}
     
+    def vote_history(self, electionID, issueID):
+        "Read vote history and return raw format"
+        res = self.es.search(index="steve", doc_type="vote_history", q = "election:%s AND issue:%s" % (electionID, issueID), size = 9999)
+        results = len(res['hits']['hits'])
+        if results > 0:
+            votes = []
+            for entry in res['hits']['hits']:
+                votes.append(entry['_source'])
+            return votes
+        return []
     
     def election_create(self,electionID, basedata):
         "Create a new election"

Modified: steve/trunk/pysteve/lib/backends/files.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/backends/files.py?rev=1728928&r1=1728927&r2=1728928&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/backends/files.py (original)
+++ steve/trunk/pysteve/lib/backends/files.py Sun Feb  7 08:56:39 2016
@@ -100,6 +100,14 @@ class FileBasedBackend:
                 return votes
         return {}
     
+    def vote_history(self, electionID, issueID):
+        issuepath = os.path.join(self.homedir, "issues", electionID, issueID) + ".json.history"
+        if os.path.isfile(issuepath):
+            with open(issuepath, "r") as f:
+                votes = json.loads(f.read())
+                f.close()
+                return votes
+        return []
     
     def election_create(self, eid, basedata):
         elpath = os.path.join(self.homedir, "issues", eid)