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/26 11:49:08 UTC

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

Author: humbedooh
Date: Thu Mar 26 10:49:08 2015
New Revision: 1669314

URL: http://svn.apache.org/r1669314
Log:
if a vote validator has been specified, run it

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=1669314&r1=1669313&r2=1669314&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/election.py (original)
+++ steve/trunk/pysteve/lib/election.py Thu Mar 26 10:49:08 2015
@@ -158,9 +158,16 @@ def vote(electionID, issueID, voterID, v
     "Casts a vote on an issue"
     votes = {}
     basedata = getBasedata(electionID)
-    if basedata:
+    issueData = getIssue(electionID, issueID)
+    if basedata and issueData:
         votehash = hashlib.sha224(basedata['hash'] + issueID + voterID + vote).hexdigest()
         
+        # Vote verification
+        voteType = getVoteType(issueData)
+        if 'vote_func' in voteType and voteType['vote_func']:
+            # This will/should raise an exception if the vote is invalid
+            voteType['vote_func'](electionID, issueID, voterID, vote)
+            
         if config.get("database", "dbsys") == "file":
             issuepath = os.path.join(homedir, "issues", electionID, issueID) + ".json"
             if os.path.isfile(issuepath + ".votes"):



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

Posted by Daniel Gruno <hu...@apache.org>.
On 2015-03-26 12:10, Greg Stein wrote:
> On Thu, Mar 26, 2015 at 5:49 AM, <hu...@apache.org> wrote:
>> ...
>> +++ steve/trunk/pysteve/lib/election.py Thu Mar 26 10:49:08 2015
>> @@ -158,9 +158,16 @@ def vote(electionID, issueID, voterID, v
>>       "Casts a vote on an issue"
>>       votes = {}
>>       basedata = getBasedata(electionID)
>> -    if basedata:
>> +    issueData = getIssue(electionID, issueID)
>> +    if basedata and issueData:
>>           votehash = hashlib.sha224(basedata['hash'] + issueID + voterID +
>> vote).hexdigest()
>>
>> +        # Vote verification
>> +        voteType = getVoteType(issueData)
>> +        if 'vote_func' in voteType and voteType['vote_func']:
>>
> Much easier:
>
>    if voteType.get('vote_func'):
>

Yeah, that'll work. I forgot that it returns a dict no matter what.
Thanks!

With regards,
Daniel.

>> ...
> Cheers,
> -g
>


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

Posted by Greg Stein <gs...@gmail.com>.
On Thu, Mar 26, 2015 at 5:49 AM, <hu...@apache.org> wrote:
>...

> +++ steve/trunk/pysteve/lib/election.py Thu Mar 26 10:49:08 2015
> @@ -158,9 +158,16 @@ def vote(electionID, issueID, voterID, v
>      "Casts a vote on an issue"
>      votes = {}
>      basedata = getBasedata(electionID)
> -    if basedata:
> +    issueData = getIssue(electionID, issueID)
> +    if basedata and issueData:
>          votehash = hashlib.sha224(basedata['hash'] + issueID + voterID +
> vote).hexdigest()
>
> +        # Vote verification
> +        voteType = getVoteType(issueData)
> +        if 'vote_func' in voteType and voteType['vote_func']:
>

Much easier:

  if voteType.get('vote_func'):


>...

Cheers,
-g