elections.sql | 12 ++- elections/admin.py | 15 ++-- elections/controllers.py | 101 +--------------------------- elections/templates/admnewe.html | 10 +- elections/templates/index.html | 6 - elections/vote.py | 138 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 168 insertions(+), 114 deletions(-)
New commits: commit 81acca32cea6ed1754d42fc7b09780ea4a654b3c Author: Nigel Jones dev@nigelj.com Date: Mon Oct 6 23:16:19 2008 +1300
Readapt /admin/newe/ (new election form) and / (main election list) for new schema, also fix up SQL schema
diff --git a/elections.sql b/elections.sql index 9674637..f3c129a 100644 --- a/elections.sql +++ b/elections.sql @@ -14,17 +14,21 @@ alias varchar(50) NOT NULL, status tinyint NOT NULL, -- Numerical value, specifying what voting method is used method tinyint NOT NULL, + shortdesc text NOT NULL, description text NOT NULL, -url text NOT NULL, + +url text, start_date timestamp NOT NULL, end_date timestamp NOT NULL, --- Show results during a running election -public_results boolean NOT NULL, +-- Are results currently embargoed? +embargoed boolean NOT NULL, +-- Number of seats elected +seats_elected integer NOT NULL, -- Does this election support nominations? allow_nominations boolean NOT NULL, -- If so, when do they have to be in by? -nomination_end timestamp NOT NULL, +nomination_end timestamp,
UNIQUE (alias), PRIMARY KEY (id) diff --git a/elections/admin.py b/elections/admin.py index bce8ff9..cede43f 100644 --- a/elections/admin.py +++ b/elections/admin.py @@ -49,13 +49,16 @@ class Admin(controllers.Controller): @expose(template="elections.templates.admnewe") def newe(self, **kw): if "submit" in kw: - if "public_results" not in kw: - pubresults=0 - embargoedres=1 + if "embargoed" not in kw: + setembargo=0 else: - pubresults=1 - embargoedres=0 - Elections(shortname=kw['shortname'],name=kw['name'],info=kw['info'],url=kw['url'],start_date=kw['startdate'],end_date=kw['enddate'],max_seats=int(kw['max_seats']),votes_per_user=1,public_results=pubresults,embargoed=embargoedres) + setembargo=1 + + if "allownominations" not in kw: + setnominations=0 + else: + setnominations=1 + Elections(alias=kw['alias'], status=0, method=0, shortdesc=kw['shortdesc'], description=kw['info'], url=kw['url'], start_date=kw['startdate'], end_date=kw['enddate'], embargoed=setembargo, seats_elected=kw['seats'], allow_nominations=setnominations, nomination_end=kw['nominationend']) raise turbogears.redirect("/") else: return dict() diff --git a/elections/templates/admnewe.html b/elections/templates/admnewe.html index 0bcb474..e1acf5d 100644 --- a/elections/templates/admnewe.html +++ b/elections/templates/admnewe.html @@ -9,14 +9,16 @@ <body> <form action="${tg.url('/admin/newe')}" method="post"> <table> - <tr><td>Election Name:</td><td><input type="text" name="name" /></td></tr> - <tr><td>Short Name:</td><td><input type="text" name="shortname" /></td></tr> + <tr><td>Election Name:</td><td><input type="text" name="shortdesc" /></td></tr> + <tr><td>Alias:</td><td><input type="text" name="alias" /></td></tr> <tr><td>Election Info:</td><td><textarea name="info" rows="5" cols="40"></textarea></td></tr> <tr><td>URL:</td><td><input type="text" name="url" /></td></tr> <tr><td>Start Date:</td><td><input type="text" name="startdate" value="yyyy-mm-dd hh:mm:ss"/></td></tr> <tr><td>End Date:</td><td><input type="text" name="enddate" value="yyyy-mm-dd hh:mm:ss"/></td></tr> - <tr><td>Seats Available:</td><td><input type="text" name="max_seats"/></td></tr> - <tr><td>Public Results:</td><td><input type="checkbox" name="public_results" /> </td></tr> + <tr><td>Seats Elected:</td><td><input type="text" name="seats"/></td></tr> + <tr><td>Embargoed?</td><td><input type="checkbox" name="embargoed" /> </td></tr> + <tr><td>Allow Nominations?</td><td><input type="checkbox" name="allownominations" /> </td></tr> + <tr><td>Until When?</td><td><input type="text" name="nominationend" /> </td></tr> <tr><td></td><td><input type="submit" name="submit" value="Submit" /></td></tr> </table> </form> diff --git a/elections/templates/index.html b/elections/templates/index.html index d1a390d..312da00 100644 --- a/elections/templates/index.html +++ b/elections/templates/index.html @@ -16,11 +16,11 @@ <th></th> </tr> <tr py:for="election in elections"> - <td>${election.name}</td> + <td>${election.shortdesc}</td> <td>${election.start_date}</td> <td>${election.end_date}</td> - <td><a href="${tg.url('/about/' + str(election.shortname))}">More Information</a></td> - <td><a py:if="election.public_results or curtime > election.end_date" href="${tg.url('/results/' + str(election.shortname))}">Results</a></td> + <td><a href="${tg.url('/about/' + str(election.alias))}">More Information</a></td> + <td><a py:if="curtime > election.end_date" href="${tg.url('/results/' + str(election.alias))}">Results</a></td> </tr> </table> </body>
commit 49c1652c1fa3e5110b0a4d71d67d39eafbad91da Author: Nigel Jones dev@nigelj.com Date: Mon Oct 6 20:15:21 2008 +1300
Actually, this might just work
diff --git a/elections/vote.py b/elections/vote.py index 14b17fb..e03be0e 100644 --- a/elections/vote.py +++ b/elections/vote.py @@ -41,7 +41,7 @@ class Vote(controllers.Controller):
@identity.require(identity.not_anonymous()) @expose(template="elections.templates.vote") - def index(self, eid=None, **kw): + def default(self, eid=None, **kw): try: eid = int(eid) election = Elections.query.filter_by(id=eid).all()[0]
commit 7fc671d6e543c3476c65f287e4cfa419c0d278d4 Author: Nigel Jones dev@nigelj.com Date: Mon Oct 6 20:14:22 2008 +1300
Split off /vote/ this won't work yet...
diff --git a/elections/controllers.py b/elections/controllers.py index d6f7008..4fa1786 100644 --- a/elections/controllers.py +++ b/elections/controllers.py @@ -32,6 +32,7 @@ from fedora.client.fas2 import AccountSystem from elections import model from elections.model import * from elections.admin import Admin +from elections.vote import Vote
import sqlalchemy
@@ -42,6 +43,9 @@ class Root(controllers.RootController): appTitle = 'Fedora Elections'
admin = Admin(appTitle) + vote = Vote(appTitle) + + @expose(template="elections.templates.index") def index(self): electlist = Elections.query.order_by(ElectionsTable.c.start_date).filter('id>0').all() @@ -70,103 +74,6 @@ class Root(controllers.RootController):
return dict(eid=eid, candidates=candidates, election=election, curtime=curtime, votergroups=votergroups, appTitle=self.appTitle)
- @identity.require(identity.not_anonymous()) - @expose(template="elections.templates.vote") - def vote(self,eid=None, **kw): - try: - eid = int(eid) - election = Elections.query.filter_by(id=eid).all()[0] - except ValueError: - try: - election = Elections.query.filter_by(shortname=eid).all()[0] - eid = election.id - except IndexError: - turbogears.flash("This election does not exist, check if you have used the correct URL.") - raise turbogears.redirect("/") - except IndexError: - turbogears.flash("This election does not exist, check if you have used the correct URL.") - raise turbogears.redirect("/") - - votergroups = LegalVoters.query.filter_by(election_id=eid).all() - foo = identity.current.groups - - match = 0 - for group in votergroups: - if group.group_name == "anycla": - if (len(identity.current.groups) > len([g for g in identity.current.groups if re.match("cla_.*",g)])): - match = 1 - elif identity.in_group(group.group_name) or group.group_name == "anyany": - match = 1 - if match == 0: - turbogears.flash("You are not in a FAS group that can vote in this election, more information can be found at the bottom of this page.") - raise turbogears.redirect("/about/" + str(eid)) - - candidates = Candidates.query.filter_by(election_id=eid).order_by(Candidates.name).all() - uservote = UserVoteCount.query.filter_by(election_id=eid, voter=turbogears.identity.current.user_name).all() - uvotes = {} - next_action = "" - - curtime = datetime.utcnow() - if election.start_date > curtime: - turbogears.flash("Voting has not yet started, sorry.") - raise turbogears.redirect("/") - elif election.end_date < curtime: - turbogears.flash("You cannot vote in this election because the end date has passed. You have been redirected to the election results") - raise turbogears.redirect("/results/" + election.shortname) - elif len(uservote) != 0: - turbogears.flash("You have already voted in this election!") - raise turbogears.redirect("/") - - # Lets do this in reverse order - if "confirm" in kw: - for c in candidates: - if str(c.id) in kw: - try: - range = int(kw[str(c.id)]) - if range >= 0 and range <= len(candidates): - uvotes[c.id] = range - else: - turbogears.flash("Invalid Ballot!") - raise turbogears.redirect("/") - except ValueError: - turbogears.flash("Invalid Ballot!") - raise turbogears.redirect("/") - for uvote in uvotes: - Votes(voter=turbogears.identity.current.user_name, candidate_id=uvote, weight=uvotes[uvote], election_id=eid, timestamp=curtime) - turbogears.flash("Your vote has been recorded, thank you!") - raise turbogears.redirect("/") - elif "vote" in kw: - turbogears.flash("Please confirm your vote!") - for c in candidates: - if str(c.id) in kw: - try: - range = int(kw[str(c.id)]) - if range > len(candidates): - turbogears.flash("Invalid data was detected for one or more candidates and was changed to zeros! Please correct and resubmit your ballot.") - uvotes[c.id] = 0 - next_action = "vote" - elif range >= 0: - uvotes[c.id] = range - else: - turbogears.flash("Invalid data was detected for one or more candidates and was changed to zeros! Please correct and resubmit your ballot.") - uvotes[c.id] = 0 - next_action = "vote" - except ValueError: - turbogears.flash("Invalid data was detected for one or more candidates and was changed to zeros! Please correct and resubmit your ballot.") - uvotes[c.id] = 0 - next_action = "vote" - else: - turbogears.flash("Invalid Ballot!") - raise turbogears.redirect("/") - if next_action != "vote": - next_action = "confirm" - else: - for c in candidates: - uvotes[c.id] = "" - next_action = "vote" - - return dict(eid=eid, candidates=candidates, election=election, nextaction=next_action, voteinfo=uvotes, appTitle=self.appTitle) - @expose(template="elections.templates.results") def results(self,eid=None): try: diff --git a/elections/vote.py b/elections/vote.py new file mode 100644 index 0000000..14b17fb --- /dev/null +++ b/elections/vote.py @@ -0,0 +1,138 @@ +# -*- coding: utf-8 -*- +# +# Copyright © 2008 Nigel Jones, Toshio Kuratomi, Ricky Zhou, Luca Foppiano All rights reserved. +# +# This copyrighted material is made available to anyone wishing to use, modify, +# copy, or redistribute it subject to the terms and conditions of the GNU +# General Public License v.2. This program is distributed in the hope that it +# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the +# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. You should have +# received a copy of the GNU General Public License along with this program; +# if not, write to the Free Software Foundation, Inc., 51 Franklin Street, +# Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat trademarks that are +# incorporated in the source code or documentation are not subject to the GNU +# General Public License and may only be used or replicated with the express +# permission of Red Hat, Inc. +# +# Author(s): Nigel Jones nigelj@fedoraproject.org +# Toshio Kuratomi toshio@fedoraproject.org +# Ricky Zhou ricky@fedoraproject.org +# Luca Foppiano lfoppiano@fedoraproject.org +# +# Report Bugs to https://www.fedorahosted.org/elections + + +# Admin functions go here (i.e. add/delete elections) + +import turbogears +from turbogears import controllers, expose, flash, redirect, config +from turbogears import identity +from elections import model +from elections.model import * + +import sqlalchemy + +from turbogears.database import session + +class Vote(controllers.Controller): + def __init__(self, appTitle): + self.appTitle = appTitle + + @identity.require(identity.not_anonymous()) + @expose(template="elections.templates.vote") + def index(self, eid=None, **kw): + try: + eid = int(eid) + election = Elections.query.filter_by(id=eid).all()[0] + except ValueError: + try: + election = Elections.query.filter_by(shortname=eid).all()[0] + eid = election.id + except IndexError: + turbogears.flash("This election does not exist, check if you have used the correct URL.") + raise turbogears.redirect("/") + except IndexError: + turbogears.flash("This election does not exist, check if you have used the correct URL.") + raise turbogears.redirect("/") + + votergroups = LegalVoters.query.filter_by(election_id=eid).all() + foo = identity.current.groups + + match = 0 + for group in votergroups: + if group.group_name == "anycla": + if (len(identity.current.groups) > len([g for g in identity.current.groups if re.match("cla_.*",g)])): + match = 1 + elif identity.in_group(group.group_name) or group.group_name == "anyany": + match = 1 + if match == 0: + turbogears.flash("You are not in a FAS group that can vote in this election, more information can be found at the bottom of this page.") + raise turbogears.redirect("/about/" + str(eid)) + + candidates = Candidates.query.filter_by(election_id=eid).order_by(Candidates.name).all() + uservote = UserVoteCount.query.filter_by(election_id=eid, voter=turbogears.identity.current.user_name).all() + uvotes = {} + next_action = "" + + curtime = datetime.utcnow() + if election.start_date > curtime: + turbogears.flash("Voting has not yet started, sorry.") + raise turbogears.redirect("/") + elif election.end_date < curtime: + turbogears.flash("You cannot vote in this election because the end date has passed. You have been redirected to the election results") + raise turbogears.redirect("/results/" + election.shortname) + elif len(uservote) != 0: + turbogears.flash("You have already voted in this election!") + raise turbogears.redirect("/") + + # Lets do this in reverse order + if "confirm" in kw: + for c in candidates: + if str(c.id) in kw: + try: + range = int(kw[str(c.id)]) + if range >= 0 and range <= len(candidates): + uvotes[c.id] = range + else: + turbogears.flash("Invalid Ballot!") + raise turbogears.redirect("/") + except ValueError: + turbogears.flash("Invalid Ballot!") + raise turbogears.redirect("/") + for uvote in uvotes: + Votes(voter=turbogears.identity.current.user_name, candidate_id=uvote, weight=uvotes[uvote], election_id=eid, timestamp=curtime) + turbogears.flash("Your vote has been recorded, thank you!") + raise turbogears.redirect("/") + elif "vote" in kw: + turbogears.flash("Please confirm your vote!") + for c in candidates: + if str(c.id) in kw: + try: + range = int(kw[str(c.id)]) + if range > len(candidates): + turbogears.flash("Invalid data was detected for one or more candidates and was changed to zeros! Please correct and resubmit your ballot.") + uvotes[c.id] = 0 + next_action = "vote" + elif range >= 0: + uvotes[c.id] = range + else: + turbogears.flash("Invalid data was detected for one or more candidates and was changed to zeros! Please correct and resubmit your ballot.") + uvotes[c.id] = 0 + next_action = "vote" + except ValueError: + turbogears.flash("Invalid data was detected for one or more candidates and was changed to zeros! Please correct and resubmit your ballot.") + uvotes[c.id] = 0 + next_action = "vote" + else: + turbogears.flash("Invalid Ballot!") + raise turbogears.redirect("/") + if next_action != "vote": + next_action = "confirm" + else: + for c in candidates: + uvotes[c.id] = "" + next_action = "vote" + + return dict(eid=eid, candidates=candidates, election=election, nextaction=next_action, voteinfo=uvotes, appTitle=self.appTitle) +
elections-devel@lists.stg.fedorahosted.org