fedora-vote newelection.py, 1.2, 1.3 voting.py, 1.5, 1.6 votingadmin.py, 1.5, 1.6 votingdb.sql, 1.3, 1.4
Toshio Ernie Kuratomi (toshio)
fedora-extras-commits at redhat.com
Thu Jun 15 14:21:15 UTC 2006
Author: toshio
Update of /cvs/fedora/fedora-vote
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv19521
Modified Files:
newelection.py voting.py votingadmin.py votingdb.sql
Log Message:
* newelection.py: Redesign to take a password from the user and update the
database. This keeps the password out of all files.
* voting.py: __init__(): Redesign to use website.get_dbh() to get a
connection as the apache user. Everything the cgi does will be done
throug the apache user.
* votingadmi.py: We no longer need a user and password here as the apache
user is being granted the permisions to do the writes to the database.
* votingdb.sql:
- Put the grant statements in to give the apache user access to the
tables it needs.
- Remove the election creation as this will now be done by newelection.py.
Index: newelection.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/newelection.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- newelection.py 12 Jun 2006 08:26:38 -0000 1.2
+++ newelection.py 15 Jun 2006 14:21:12 -0000 1.3
@@ -3,9 +3,16 @@
# into the electiondb
import sys
+import getpass
+sys.path.append('/var/www/html/admin/accounts')
+
+import pgdb
import website
-import votingadmin
+
+dbName = 'elections'
+dbHost = 'db1.fedora.phx.redhat.com'
+dbUser = 'electionsuser'
electionName = 'FESCo 2006'
start = '2006-06-08'
@@ -15,9 +22,9 @@
votingGroups = ('cvsextras',)
candidates = ('awjb',
- 'spot',
- 'rdieter',
- 'kevin',
+ 'spot',
+ 'rdieter',
+ 'kevin',
'ausil',
'c4chris',
'katzj',
@@ -34,6 +41,11 @@
groupList = []
candList = []
+# Establish the connection to the elections database
+dbPass = getpass.getpass('Enter the database password: ')
+db = pgdb.connect(database=dbName, host=dbHost, user=dbUser, password=dbPass)
+dbCmd = db.cursor()
+
dbh = website.get_dbh()
print "Check that these are the candidates you were expecting"
for cand in candidates:
@@ -59,25 +71,28 @@
if letter[:1] != 'y' and letter[:1] != 'Y':
sys.exit(1)
-# Save the candidates
-election = votingadmin.ElectionAdmin(dbh, electionName)
+# Create the election
query = "insert into election (start_date, end_date, common_name, max_seats)" \
" values('%s', '%s', '%s', '%s')" % (start, end, electionName, seats)
-election.dbCmd.execute(query)
+dbCmd.execute(query)
+# Get the id for the new election
+dbCmd.execute("select id from election where common_name = '%s'" % electionName)
+electionId = dbCmd.fetchall()[0][0]
+
+# Save the candidates
for candNum in candList:
query = "insert into candidates (id, election_id) values ('%s', '%s')" \
- % (candNum, election.electionId)
+ % (candNum, electionId)
print query
- election.dbCmd.execute(query)
+ dbCmd.execute(query)
# Save the groups
for groupNum in groupList:
query = "insert into legalVoters (election_id, group_id)" \
- " values ('%s', '%s')" % (election.electionId, groupNum)
+ " values ('%s', '%s')" % (electionId, groupNum)
print query
- election.dbCmd.execute(query)
+ dbCmd.execute(query)
# Commit the changes
-election.dbCmd.execute('COMMIT')
-
+dbCmd.execute('COMMIT')
Index: voting.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/voting.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- voting.py 12 Jun 2006 08:26:38 -0000 1.5
+++ voting.py 15 Jun 2006 14:21:12 -0000 1.6
@@ -24,16 +24,12 @@
class Election(object):
electionDB = 'elections'
- dbHost = 'db1.fedora.phx.redhat.com'
- dbUser = 'electionsuser'
- dbPass = 't3stp at ssw0rd4el'
def __init__(self, dbh, commonName):
'''Initialize the election with the database backend.'''
self.commonName = commonName
- self.dbh = dbh;
- self.db = pgdb.connect(database=self.electionDB, host=self.dbHost,
- user=self.dbUser, password=self.dbPass)
+ self.dbh = dbh
+ self.db = website.get_dbh(self.electionDB)
self.dbCmd = self.db.cursor()
self.dbCmd.execute("select id from election"
" where common_name = '%s'" % commonName)
@@ -63,9 +59,6 @@
' db for %s' % user
# Ask the accounts db if user belongs to that group.
- ### FIXME: website.get_user_group looks like it might be broken to
- # me. Verify that the format string in dbc.execute really does what
- # we want.
groups = website.get_user_groups(self.dbh, userId)
for group in groups:
if group[0] in self.votingGroups:
Index: votingadmin.py
===================================================================
RCS file: /cvs/fedora/fedora-vote/votingadmin.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- votingadmin.py 13 Jun 2006 07:29:26 -0000 1.5
+++ votingadmin.py 15 Jun 2006 14:21:12 -0000 1.6
@@ -15,8 +15,10 @@
from voting import *
class ElectionAdmin(Election):
- dbUser = 'notguest'
- dbPass = 'notguest'
+ def __init__(self, dbh, commonName):
+ Election.__init__(self, dbh, commonName)
+ # If we need to customize the read-write interface (different user and
+ # password or some such, do it here.)
def process_ballot(self, username, ballot):
'''Validate the ballot and enter it into the database.
Index: votingdb.sql
===================================================================
RCS file: /cvs/fedora/fedora-vote/votingdb.sql,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- votingdb.sql 10 Jun 2006 06:42:45 -0000 1.3
+++ votingdb.sql 15 Jun 2006 14:21:12 -0000 1.4
@@ -55,4 +55,11 @@
create view tallysheet as
select sum(points) as vote_count, id, candidates.election_id from candidates, votes where candidates.id = candidate_id group by id, candidates.election_id order by candidates.election_id, vote_count desc;
--- insert into election (start_date, end_date, common_name, max_seats) values('2006-05-29', '2006-06-05', 'FESCo 2006', '13');
+grant select on tallysheet to apache;
+grant select on election to apache;
+grant select on candidates to apache;
+grant select on legalVoters to apache;
+grant select on ballots to apache;
+grant insert on ballots to apache;
+grant insert on votes to apache;
+grant update on ballots_id_seq to apache;
More information about the scm-commits
mailing list