fedora-vote castvote.cgi,1.6,1.7 votingadmin.py,1.4,1.5
Toshio Ernie Kuratomi (toshio)
fedora-extras-commits at redhat.com
Tue Jun 13 07:29:28 UTC 2006
Author: toshio
Update of /cvs/fedora/fedora-vote
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv27010
Modified Files:
castvote.cgi votingadmin.py
Log Message:
* castvote.cgi:
- Remove the <pre> tags around printing the receipt.
- Move checks for whether the election is in progress and whether the
user is authorized to vote inside the process_ballot() method.
* votingadmin.py: Move checks for election in progress and whether the
voter is authorized to vote into process_ballot().
Index: castvote.cgi
===================================================================
RCS file: /cvs/fedora/fedora-vote/castvote.cgi,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- castvote.cgi 13 Jun 2006 07:03:54 -0000 1.6
+++ castvote.cgi 13 Jun 2006 07:29:26 -0000 1.7
@@ -27,9 +27,7 @@
<p>
Thank you for voting in the %s Election.
</p>
- <pre>
%s
- </pre>
''' % (electionName, receipt)
return content
@@ -46,10 +44,6 @@
title=pageTitle, require_auth = True)
try:
election = votingadmin.ElectionAdmin(dbh=dbh, commonName=electionName)
- ### FIXME: These checks need to be performed within process_ballot; not
- # here.
- inProgress = election.occurring()
- authorized = election.authorize_user(username)
except (voting.VotingError, pgdb.Error), e:
website.send_email(voting.sendAs, voting.sendErrorsTo, 'Voting Error',
'''The Fedora Voting Application failed to retrieve information
@@ -63,49 +57,49 @@
' recast your ballot later.</p>'
else:
- # 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.startswith('cand'):
- ballotCandidates[entry[4:]] = form.getvalue(entry)
- try:
- receipt = election.process_ballot(username, ballotCandidates)
- except voting.VotingError, e:
- if e.args[0] == 'Already voted in this election':
- content = '<p class="error">You have already submitted a' \
- ' ballot in this election. You can only vote once.</p>'
- else:
- website.send_email(voting.sendAs, voting.sendErrorsTo,
- 'Voting Error',
- '''The Fedora Voting Application failed to save a
+ # Extract the candidates from the web form
+ ballotCandidates = {}
+ for entry in form.keys():
+ if entry.startswith('cand'):
+ ballotCandidates[entry[4:]] = form.getvalue(entry)
+ try:
+ receipt = election.process_ballot(username, ballotCandidates)
+ except voting.VotingError, e:
+ # Authorization or validation failed
+ if e.args[0] == 'Already voted in this election':
+ content = '<p class="error">You have already submitted a' \
+ ' ballot in this election. You can only vote once.</p>'
+ elif e.args[0] == '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 e.args[0] == 'Election is not in progress':
+ content = '<p class="error">The ' + electionName + ' Election' \
+ ' is not currently taking place. You cannot vote in' \
+ ' it at this time.</p>'
+ else:
+ 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 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, pg.Error), e:
- website.send_email(voting.sendAs, voting.sendErrorsTo,
- '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, 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.''' %(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' \
- ' 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, 'http://www.fedoraproject.org')
Index: votingadmin.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/votingadmin.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- votingadmin.py 13 Jun 2006 07:03:54 -0000 1.4
+++ votingadmin.py 13 Jun 2006 07:29:26 -0000 1.5
@@ -35,7 +35,6 @@
candidates = self.candidates or self.get_candidates()
tally = {}
receiptList = ['<p>You voted for:</p>', '<ul>']
-
for ballotCandidate in ballot.keys():
if int(ballotCandidate) not in candidates:
raise VotingError, 'Unknown candidate'
@@ -55,6 +54,14 @@
if self.already_cast_vote(username):
raise VotingError, 'Already voted in this election'
+ # Check that the voter is authorized to vote in this election
+ if not self.authorize_user(username):
+ raise VotingError, 'Not authorized'
+
+ # Check that the election is taking place
+ if self.occurring():
+ raise VotingError, 'Election is not in progress'
+
# Enter the ballot information into the database
userId = website.get_user_id(self.dbh, username)
if not userId:
More information about the fedora-extras-commits
mailing list