fedora-vote castvote.cgi, 1.3, 1.4 vote.cgi, 1.2, 1.3 voting.py, 1.2, 1.3

Toshio Ernie Kuratomi (toshio) fedora-extras-commits at redhat.com
Sat Jun 10 05:24:10 UTC 2006


Author: toshio

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

Modified Files:
	castvote.cgi vote.cgi voting.py 
Log Message:
* castvote.cgi, vote.cgi:
  - Call website.handle_auth() to verify the username and password before
    and popup a login screen if they fail t validate.
  - Include the exception's message when emailing an admin.
  - Make the validation checks only run if there were no exceptions.
    If they are run unconditionally, we stumble because the information
    may not have been retrieved from the database.
* voting.py:
  - Correct a reference to the db to use self.db.
  - Correct typo where electionId was not plural.
  - occurring(): Do not check for multiple matching elections, this was
    checked when the Election object was created.



Index: castvote.cgi
===================================================================
RCS file: /cvs/fedora/fedora-vote/castvote.cgi,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- castvote.cgi	10 Jun 2006 03:21:05 -0000	1.3
+++ castvote.cgi	10 Jun 2006 05:24:08 -0000	1.4
@@ -30,60 +30,64 @@
 
     pageTitle = 'Vote for %s Submitted' % electionName
     website.print_header(pageTitle, username)
+    website.handle_auth(username, password, form, 'castvote.cgi',
+            title=pageTitle, require_auth = True)
     try:
         election = voting.Election(dbh=dbh, commonName=electionName)
         inProgress = election.occurring()
         authorized = election.authorize_user(username)
-    except (voting.VotingError, pgdb.Error):
+    except (voting.VotingError, pgdb.Error), e:
         website.send_email(voting.sendAs, voting.sendErrorsTo, 'Voting Error',
                 '''The Fedora Voting Application failed to retrieve information
 from the database necessary to save a vote from %s for The %s Election,  The
-error occurred from castvote.cgi.''' % (username, electionName))
+error occurred from castvote.cgi.  It's message was: %s'''
+                % (username, electionName, str(e)))
         content = '<p class="error">Failed to get information on the election' \
                 ' from the database.  Your vote has not been processed.  An' \
                 ' email has been sent to the voting administrators to look' \
                 ' at what might be broken in the software.  Please try to' \
                 ' recast your ballot later.</p>'
 
-    # Authorize the user to vote and validate their ballot
-    if inProgress:
-        content = '<p class="error">The ' + electionName + ' Election is not' \
-                ' currently taking place.  You cannot vote in it at this' \
-                ' time.</p>'
-    elif not authorized:
-        content = '<p class="error">You are not a member of one of the' \
-                ' groups eligible to vote in this election.  If you think' \
-                'you should be, please contact someone ASAP.</p>'
     else:
-        # Extract the candidates from the web form
-        ballotCandidates = []
-        for entry in form.keys():
-            if entry.beginswith('cand'):
-                ballotCandidate[entry[4:]] = form.getvalue(entry)
-        try:
-            receipt = election.process_ballot(username, ballotCandidates)
-        except VotingError, e:
-            website.send_email(voting.sendAs, voting.sendErrorsTo,
-                    'Voting Error',
-                    '''The Fedora Voting Application failed to save a ballot
+        # Authorize the user to vote and validate their ballot
+        if inProgress:
+            content = '<p class="error">The ' + electionName + ' Election is' \
+                    ' not currently taking place.  You cannot vote in it at' \
+                    ' this time.</p>'
+        elif not authorized:
+            content = '<p class="error">You are not a member of one of the' \
+                    ' groups eligible to vote in this election.  If you think' \
+                    'you should be, please contact someone ASAP.</p>'
+        else:
+            # Extract the candidates from the web form
+            ballotCandidates = []
+            for entry in form.keys():
+                if entry.beginswith('cand'):
+                    ballotCandidate[entry[4:]] = form.getvalue(entry)
+            try:
+                receipt = election.process_ballot(username, ballotCandidates)
+            except 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)))
-            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,
-                'Database Error',
-                '''The Fedora Voting Application was unable to save a ballot
+                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,
+                    '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)))
-            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 the' \
-                    ' problem.  Please try to vote again later. </p>'
-        else:
-            content = make_thank_you(electionName, receipt)
+                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' \
+                        ' the problem.  Please try to vote again later. </p>'
+            else:
+                content = make_thank_you(electionName, receipt)
 
     print content
     website_print_footer(pageTitle, nextPage)


Index: vote.cgi
===================================================================
RCS file: /cvs/fedora/fedora-vote/vote.cgi,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- vote.cgi	10 Jun 2006 03:21:05 -0000	1.2
+++ vote.cgi	10 Jun 2006 05:24:08 -0000	1.3
@@ -73,6 +73,9 @@
     content = ''
     pageTitle = 'Ballot for %s Election' % electionName
     website.print_header(pageTitle, auth_username)
+    website.handle_auth(auth_username, auth_password, form, 'vote.cgi',
+            title=pageTitle, require_auth = True)
+
     try:
         election = voting.Election(dbh=dbh, commonName=electionName)
         authorized = election.authorize_user(auth_username)
@@ -80,27 +83,29 @@
         alreadyCast = election.already_cast_vote(auth_username)
         candidates = election.get_candidates()
         openSeats = election.votes_to_allocate()
-    except (voting.VotingError, pgdb.Error):
+    except (voting.VotingError, pgdb.Error), e:
         website.send_email(voting.sendAs, voting.sendErrorsTo, 'Voting Error',
                 '''The Fedora Voting Application failed to pull information
 from the database in order to register a vote for %s during the %s Election.
-The error occurred in vote.cgi.''' % (auth_username, electionName))
+The error occurred in vote.cgi.  The error was: %s''' 
+            % (auth_username, electionName, str(e)))
         content = '<p class="error">Failed to get information on the election' \
                 ' from the database.  An email has been sent to the voting' \
-                'administrators.  Please try to vote again later.</p>'
-    if occurs:
-        content = '<p class="error">The ' + electionName + ' election is not' \
-                ' currently taking place.  You cannot vote in it at this' \
-                ' time.</p>'
-    elif not authorized:
-        content = '<p class="error">You are not a member of one of the' \
-                ' groups eligible to vote in this election.  If you think' \
-                'you should be, please contact someone ASAP.</p>'
-    elif alreadyCast:
-        content = '<p class="error">You have already voted in this election.' \
-                '  You can only vote once.</p>'
+                ' administrators.  Please try to vote again later.</p>'
     else:
-        content = make_ballot(candidates, electionName, openSeats)
+        if occurs:
+            content = '<p class="error">The ' + electionName + ' election is not' \
+                    ' currently taking place.  You cannot vote in it at this' \
+                    ' time.</p>'
+        elif not authorized:
+            content = '<p class="error">You are not a member of one of the' \
+                    ' groups eligible to vote in this election.  If you think' \
+                    ' you should be, please contact someone ASAP.</p>'
+        elif alreadyCast:
+            content = '<p class="error">You have already voted in this election.' \
+                    '  You can only vote once.</p>'
+        else:
+            content = make_ballot(candidates, electionName, openSeats)
         
     print content
     website.print_footer(pageTitle)


Index: voting.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/voting.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- voting.py	10 Jun 2006 02:57:52 -0000	1.2
+++ voting.py	10 Jun 2006 05:24:08 -0000	1.3
@@ -24,9 +24,9 @@
 
 class Election(object):
     electionDB = 'elections'
-    dbHost = 'localhost'
-    dbUser = 'guest'
-    dbPass = 'guest'
+    dbHost = 'db1.fedora.phx.redhat.com'
+    dbUser = 'electionsuser'
+    dbPass = 't3stp at ssw0rd4el'
 
     def __init__(self, dbh, commonName):
         '''Initialize the election with the database backend.'''
@@ -34,16 +34,16 @@
         self.dbh = dbh;
         self.db = pgdb.connect(database=self.electionDB, host=self.dbHost,
                 user=self.dbUser, password=self.dbPass)
-        self.dbCmd = db.cursor()
+        self.dbCmd = self.db.cursor()
         self.dbCmd.execute("select id from election"
                 " where common_name = '%s'" % commonName)
         electionIds = self.dbCmd.fetchall()
-        if len(electionId) < 1:
+        if len(electionIds) < 1:
             raise VotingError, 'Unknown Election %s' % (commonName,)
-        elif len(electionId > 1):
+        elif len(electionIds) > 1:
             raise VotingError, 'More than one election returned for %s' % (commonName,)
         else:
-            self.electionId = electionId[0][0]
+            self.electionId = electionIds[0][0]
         self.clear_cache()
 
     def authorize_user(self, user):
@@ -93,9 +93,6 @@
             dates = self.dbCmd.fetchall()
             if len(dates) < 1:
                 raise VotingError, 'Unknown election %s' % self.electionId
-            elif len(electionId > 1):
-                raise VotingError, 'More than one election matched %s' % (
-                        self.electionId,)
             else:
                 self.startDate = dates[0][0]
                 self.endDate = dates[0][1]




More information about the scm-commits mailing list