On 2015-03-23 22:03, Jim Jagielski wrote:
Does it just dim it? People can vote more than once...
They can vote as many times as they like, that will just override their previous vote.
This is just a helpful display tweak, it doesn't prevent anything.

Essentially, this just sets a hasVoted boolean for when you fetch the issue data via the API, it doesn't do much else.

With regards,
Daniel.
Thx
On Mar 20, 2015, at 5:34 PM, humbed...@apache.org wrote:

Author: humbedooh
Date: Fri Mar 20 21:34:50 2015
New Revision: 1668159

URL: http://svn.apache.org/r1668159
Log:
detect if an issue has already been voted on once, dim the issue if so.

Modified:
    steve/trunk/pytest/www/cgi-bin/lib/voter.py
    steve/trunk/pytest/www/cgi-bin/rest_voter.py
    steve/trunk/pytest/www/htdocs/js/steve_rest.js

Modified: steve/trunk/pytest/www/cgi-bin/lib/voter.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/lib/voter.py?rev=1668159&r1=1668158&r2=1668159&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/lib/voter.py (original)
+++ steve/trunk/pytest/www/cgi-bin/lib/voter.py Fri Mar 20 21:34:50 2015
@@ -46,6 +46,16 @@ def remove(election, basedata, email):
         f.close()
     return uid, xhash

+def hasVoted(election, issue, uid):
+    issue = issue.strip(".json")
+    path = os.path.join(homedir, "issues", election, issue)
+    votes = {}
+    if os.path.isfile(path + ".json.votes"):
+        with open(path + ".json.votes", "r") as f:
+            votes = json.loads(f.read())
+            f.close()
+    return True if uid in votes else False
+
def email(rcpt, subject, message):
     sender = config.get("email", "sender")
     signature = config.get("email", "signature")

Modified: steve/trunk/pytest/www/cgi-bin/rest_voter.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/rest_voter.py?rev=1668159&r1=1668158&r2=1668159&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_voter.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_voter.py Fri Mar 20 21:34:50 2015
@@ -67,10 +67,6 @@ if pathinfo:
                     with open(elpath + "/basedata.json", "r") as f:
                         basedata = json.loads(f.read())
                         f.close()
-
-                    if 'hash' in basedata:
-                        del basedata['hash']
-
                     issues = [ f for f in listdir(elpath) if os.path.isfile(os.path.join(elpath,f)) and f != 
"basedata.json" and f != "voters.json" and f.endswith(".json")]
                     for issue in issues:
                         try:
@@ -80,11 +76,14 @@ if pathinfo:
                                 entry['id'] = issue.strip(".json")
                                 entry['APIURL'] = "https://%s/steve/voter/view/%s/%s"; % 
(os.environ['SERVER_NAME'], election, issue.strip(".json"))
                                 entry['prettyURL'] = "https://%s/steve/ballot?%s/%s"; % 
(os.environ['SERVER_NAME'], election, issue.strip(".json"))
+                                entry['hasVoted'] = voter.hasVoted(election, 
issue, voterid)
                                 js.append(entry)
                         except Exception as err:
                             response.respond(500, {'message': 'Could not load 
issues: %s' % err})
                 except Exception as err:
                     response.respond(500, {'message': 'Could not load base 
data: %s' % err})
+                if 'hash' in basedata:
+                    del basedata['hash']
                 response.respond(200, {'base_data': basedata, 'issues': js, 'baseurl': 
"https://%s/steve/election?%s"; % (os.environ['SERVER_NAME'], election)})
             else:
                 response.respond(404, {'message': 'No such election'})

Modified: steve/trunk/pytest/www/htdocs/js/steve_rest.js
URL: 
http://svn.apache.org/viewvc/steve/trunk/pytest/www/htdocs/js/steve_rest.js?rev=1668159&r1=1668158&r2=1668159&view=diff
==============================================================================
--- steve/trunk/pytest/www/htdocs/js/steve_rest.js (original)
+++ steve/trunk/pytest/www/htdocs/js/steve_rest.js Fri Mar 20 21:34:50 2015
@@ -240,6 +240,13 @@ function renderElectionFrontpage(respons
                no.setAttribute("class", "issueNumber")
                no.innerHTML = (s)
                
+               if (issue.hasVoted) {
+                       outer.setAttribute("style", "background: linear-gradient(to 
bottom, #d8d8d8 0%,#aaaaaa 100%);")
+                       outer.setAttribute("title", "Notice: You have already voted 
once on this issue")
+               } else {
+                       outer.setAttribute("title", "You have not yet voted on this 
issue");
+               }
+               
                // Add issue
                var inner = document.createElement('span')
                inner.innerHTML = issue.id + ": " + issue.title;
@@ -302,6 +309,12 @@ function renderElectionBulk(response, el
                        outer.style.marginBottom = "15px"
                        
                        // details
+                       if (issue.hasVoted) {
+                               outer.setAttribute("style", "background: 
linear-gradient(to bottom, #d8d8d8 0%,#aaaaaa 100%);")
+                               outer.setAttribute("title", "Notice: You have 
already voted once on this issue")
+                       } else {
+                               outer.setAttribute("title", "You have not yet voted 
on this issue");
+                       }
                        
                        var statement = document.createElement('div')
             statement.setAttribute("class", "statement_marker")
@@ -403,6 +416,6 @@ function castVoteCallback(code, response
        if (code == 200) {
                //code
        } else {
-               //alert(response.message)
+               alert(response.message)
        }
}
\ No newline at end of file



Reply via email to