fedora-vote castvote.cgi, 1.4, 1.5 newelection.py, 1.1, 1.2 vote.cgi, 1.3, 1.4 voting.py, 1.4, 1.5 votingadmin.py, 1.2, 1.3

Toshio Ernie Kuratomi (toshio) fedora-extras-commits at redhat.com
Mon Jun 12 08:26:40 UTC 2006


Author: toshio

Update of /cvs/fedora/fedora-vote
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv26556

Modified Files:
	castvote.cgi newelection.py vote.cgi voting.py votingadmin.py 
Log Message:
* castvote.cgi:
  - Create a read-write connection to the database via votingadmin instead
    of voting's read-only connection.
  - ballotCandidates should be declared a dict.
  - Change beginswith() to startswith().
  - Fix ballotCandidates typo.
  - Namespace VotingError exception.
  - Catch pg.Error as well.  Python's DB API 2.0 specifies that all errors
    should subclass the [db module].Error exception but apparently pgdb
    does this wrong.
  - Fix username typo.
  - Add fedoraproject.org as the page to return to after the election.
* newelection.py:
  - Add votingGroups that defines the list of groups that can vote.
  - Fix user input to work for multiple confirm messages.
  - Add logic to add the legalVoters groups as well.
* vote.cgi:
  - Change javascript attribute access from dot notation to subscript.
    This handles spaces in the atttribute names (ex: 'FESCo 2006').
  - Add a title.
  - Fix printing of the candidate form.
* voting.py: Get the candidates human_name instead of their username.
* votingadmin.py:
  - Fix checking for too many votes.  Have to check versus the ballot, not
    the total number of candidates.
  - Fix different key types (string vs int) in dicts returned from the form
    and the database.



Index: castvote.cgi
===================================================================
RCS file: /cvs/fedora/fedora-vote/castvote.cgi,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- castvote.cgi	10 Jun 2006 05:24:08 -0000	1.4
+++ castvote.cgi	12 Jun 2006 08:26:38 -0000	1.5
@@ -4,9 +4,11 @@
 import cgi
 import os
 import pgdb
+import pg
 
 import website
 import voting
+import votingadmin
 
 electionName = 'FESCo 2006'
 
@@ -33,7 +35,7 @@
     website.handle_auth(username, password, form, 'castvote.cgi',
             title=pageTitle, require_auth = True)
     try:
-        election = voting.Election(dbh=dbh, commonName=electionName)
+        election = votingadmin.ElectionAdmin(dbh=dbh, commonName=electionName)
         inProgress = election.occurring()
         authorized = election.authorize_user(username)
     except (voting.VotingError, pgdb.Error), e:
@@ -60,28 +62,28 @@
                     'you should be, please contact someone ASAP.</p>'
         else:
             # Extract the candidates from the web form
-            ballotCandidates = []
+            ballotCandidates = {}
             for entry in form.keys():
-                if entry.beginswith('cand'):
-                    ballotCandidate[entry[4:]] = form.getvalue(entry)
+                if entry.startswith('cand'):
+                    ballotCandidates[entry[4:]] = form.getvalue(entry)
             try:
                 receipt = election.process_ballot(username, ballotCandidates)
-            except VotingError, e:
+            except voting.VotingError, e:
                 website.send_email(voting.sendAs, voting.sendErrorsTo,
                         'Voting Error',
                         '''The Fedora Voting Application failed to save a ballot
 cast by %s in the %s election.  It received a VotingError with message %s in
-catvote.cgi.''' % (username, electionName, str(e)))
+castvote.cgi.''' % (username, electionName, str(e)))
                 content = '<p class="error">The ballot you have attempted to' \
                         ' cast is not valid.  The admins have been emailed to' \
                         ' see why the website is trying to send malformed' \
                         ' ballots. </p>'
-            except pgdb.Error, e:
-                website.send_email(voting.sendAs, voting.sendErrorTo,
+            except (pgdb.Error, pg.Error), e:
+                website.send_email(voting.sendAs, voting.sendErrorsTo,
                     'Database Error',
                     '''The Fedora Voting Application was unable to save a ballot
 cast by %s in the %s election.  It received a DatabaseError with the message
-%s in castvote.cgi.''' %(usename, electionName, str(e)))
+%s in castvote.cgi.''' %(username, electionName, str(e)))
                 content = '<p class="error">There was a database error while' \
                         ' processing your ballot.  The ballot was not saved.' \
                         ' The voting admins have been emailed to look into' \
@@ -90,5 +92,5 @@
                 content = make_thank_you(electionName, receipt)
 
     print content
-    website_print_footer(pageTitle, nextPage)
+    website.print_footer(pageTitle, 'http://www.fedoraproject.org')
     dbh.close()


Index: newelection.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/newelection.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- newelection.py	10 Jun 2006 06:42:45 -0000	1.1
+++ newelection.py	12 Jun 2006 08:26:38 -0000	1.2
@@ -12,6 +12,8 @@
 end = '2006-06-20'
 seats = '13'
 
+votingGroups = ('cvsextras',)
+
 candidates = ('awjb',
     'spot', 
     'rdieter', 
@@ -29,6 +31,7 @@
     'tibbs',
     'wtogami',
     'skvidal')
+groupList = []
 candList = []
 
 dbh = website.get_dbh()
@@ -40,10 +43,23 @@
     candList.append(id)
 
 print "Were those the correct candidates? (y/n)"
-letter = sys.stdin.read(1)
-if letter != 'y' and letter != 'Y':
+letter = sys.stdin.readline()
+if letter[:1] != 'y' and letter[:1] != 'Y':
+    sys.exit(1)
+
+print "Check that these are the groups you want to vote in this election"
+for group in votingGroups:
+    gid = website.get_group_id(dbh, group)
+    gname = website.get_group_name(dbh, gid)
+    print '%s -- %s' % (gname, gid)
+    groupList.append(gid)
+    
+print "Were those the correct groups? (y/n)"
+letter = sys.stdin.readline()
+if letter[:1] != 'y' and letter[:1] != 'Y':
     sys.exit(1)
 
+# Save the candidates
 election = votingadmin.ElectionAdmin(dbh, electionName)
 query = "insert into election (start_date, end_date, common_name, max_seats)" \
         " values('%s', '%s', '%s', '%s')" % (start, end, electionName, seats)
@@ -55,5 +71,13 @@
     print query
     election.dbCmd.execute(query)
 
+# Save the groups
+for groupNum in groupList:
+    query = "insert into legalVoters (election_id, group_id)" \
+            " values ('%s', '%s')"  % (election.electionId, groupNum)
+    print query
+    election.dbCmd.execute(query)
+
+# Commit the changes
 election.dbCmd.execute('COMMIT')
 


Index: vote.cgi
===================================================================
RCS file: /cvs/fedora/fedora-vote/vote.cgi,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- vote.cgi	10 Jun 2006 05:24:08 -0000	1.3
+++ vote.cgi	12 Jun 2006 08:26:38 -0000	1.4
@@ -12,20 +12,20 @@
 
 def make_ballot(candidates, ballotName, openSeats):
     '''Return a string representing an html ballot.'''
-    content = ['''<SCRIPT LANGUAGE="javascript">
+    content = ['''<SCRIPT type="text/javascript">
     function KeepCount() {
         var NewCount = 0
     ''']
     for jcandidateNumber in candidates.keys():
         content.append('''
-        if (document.%s.cand%d.checked) {
+        if (document['%s']['cand%d'].checked) {
             NewCount = NewCount + 1
         }
         ''' % (ballotName, jcandidateNumber))
     content.append('''
         if (NewCount > %d) {
             alert("You may only vote for %d candidates in this election.")
-            document.%s; 
+            document['%s']; 
             return false;
         }
         ''' % (openSeats, openSeats, ballotName))
@@ -33,6 +33,7 @@
         }
         </SCRIPT>
         <form NAME="%s" method="post" action="castvote.cgi"/>
+          <h2>Ballot for %s Election</h2>
           <p><b>Vote for %d candidates:</b></p>
             <table>
               <tr>
@@ -41,7 +42,7 @@
                 <th>IRC Nick</th>
                 <th>Vote</th>
               </tr>
-        ''' % (ballotName, openSeats))
+        ''' % (ballotName, ballotName, openSeats))
     for (candidateNumber, candidateTuple) in candidates.items():
         content.append('''
               <tr>
@@ -54,7 +55,7 @@
                 </td>
               </tr>
         ''' % (candidateTuple[0], candidateTuple[1], candidateTuple[2],
-            candidateNumber, candidateName))
+            candidateNumber, candidateTuple[0]))
     content.append('''
             </table>
             <p class="votesubmission">


Index: voting.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/voting.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- voting.py	10 Jun 2006 06:42:45 -0000	1.4
+++ voting.py	12 Jun 2006 08:26:38 -0000	1.5
@@ -118,7 +118,7 @@
                 if not candInfo:
                     raise VotingError, 'Candidate %s not in the accounts db' % \
                             candidate[0]
-                self.candidates[candidate[0]] = (candInfo['username'],
+                self.candidates[candidate[0]] = (candInfo['human_name'],
                         candInfo['email'], candInfo['ircnick'])
         return self.candidates
 


Index: votingadmin.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/votingadmin.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- votingadmin.py	10 Jun 2006 02:57:52 -0000	1.2
+++ votingadmin.py	12 Jun 2006 08:26:38 -0000	1.3
@@ -27,7 +27,7 @@
         '''
         # Check that no more than openSeats were voted for
         openSeats = self.seats or self.votes_to_allocate()
-        if len(candidates) > openSeats:
+        if len(ballot) > openSeats:
             raise VotingError, 'Voted for too many candidates'
 
         # Make sure all the candidates voted for appear in the database and
@@ -37,11 +37,11 @@
         receiptList = ['<p>You voted for:</p>', '<ul>']
         
         for ballotCandidate in ballot.keys():
-            if ballotCandidate not in candidates:
+            if int(ballotCandidate) not in candidates:
                 raise VotingError, 'Unknown candidate'
             # Check that candidateName and id match, otherwise the html ballot
             # is coded with mismatching names to candidate ids.
-            if candidates[ballotCandidate][0] != ballot[ballotCandidate]:
+            if candidates[int(ballotCandidate)][0] != ballot[ballotCandidate]:
                 raise VotingError, 'Candidate ID does not match Candidate Name'
             if tally.has_key(ballotCandidate):
                 raise VotingError, 'Candidate ID entered more than once'




More information about the fedora-extras-commits mailing list