elections/admin.py | 5 +++-- elections/controllers.py | 24 ++++++++++++++++++++---- elections/templates/about.html | 2 +- elections/templates/admnewe.html | 2 +- elections/templates/results.html | 2 +- elections/templates/vote.html | 2 +- elections/vote.py | 12 ++++++++++-- 7 files changed, 37 insertions(+), 12 deletions(-)
New commits: commit 25973c15f37ca000a5912ac61924884d0bc44128 Author: Nigel Jones dev@nigelj.com Date: Tue Oct 7 18:37:39 2008 +1300
Grab Candidate's name from FAS when election is set to usefas - part 2/2
diff --git a/elections/controllers.py b/elections/controllers.py index 7ca713b..89d2cd4 100644 --- a/elections/controllers.py +++ b/elections/controllers.py @@ -100,6 +100,12 @@ class Root(controllers.RootController): turbogears.flash("This election does not exist, check if you have used the correct URL.") raise turbogears.redirect("/")
+ usernamemap = {} + + if election.usefas: + for c in election.candidates: + usernamemap[c.id] = self.fas.person_by_username(c.name)['human_name'] + curtime = datetime.utcnow() if election.end_date > curtime: turbogears.flash("We are sorry, the results for this election cannot be viewed at this time because the election is still in progress.") @@ -111,7 +117,7 @@ class Root(controllers.RootController): turbogears.flash("We are sorry, the results for this election cannot be viewed because they are currently embargoed pending formal announcement.") raise turbogears.redirect("/") votecount = VoteTally.query.filter_by(election_id=eid).order_by(VoteTally.novotes.desc()).all() - return dict(votecount=votecount, election=election, appTitle=self.appTitle) + return dict(votecount=votecount, usernamemap=usernamemap, election=election, appTitle=self.appTitle)
@expose(template="elections.templates.login", allow_json=True) def login(self, forward_url=None, previous_url=None, *args, **kw): diff --git a/elections/templates/results.html b/elections/templates/results.html index d3e4a51..d2d142d 100644 --- a/elections/templates/results.html +++ b/elections/templates/results.html @@ -12,7 +12,7 @@ <p py:if="election.url"><a href="${election.url}">[More Information]</a></p> <table border="1" cellpadding="1"> <tr py:for="candcount in votecount"> - <td>${candcount.candidate.name} <small py:if="candcount.candidate.url"><a href="${candcount.candidate.url}">[info]</a></small></td> + <td><py:choose test="election.usefas"><py:when test="0">${candcount.candidate.name}</py:when><py:when test="1">${usernamemap[candcount.candidate.id]}</py:when></py:choose> <small py:if="candcount.candidate.url"><a href="${candcount.candidate.url}">[info]</a></small></td> <td>${candcount.novotes}</td> </tr> </table> diff --git a/elections/templates/vote.html b/elections/templates/vote.html index 39c7248..66dd80d 100644 --- a/elections/templates/vote.html +++ b/elections/templates/vote.html @@ -30,7 +30,7 @@ <form action="${tg.url('/vote/' + str(election.id))}" method="post"> <table border="1" cellpadding="1"> <tr py:for="candidate in candidates"> - <td>${candidate.name} <small py:if="candidate.url"><a href="${candidate.url}">[info]</a></small></td> + <td><py:choose test="election.usefas"><py:when test="0">${candidate.name}</py:when><py:when test="1">${usernamemap[candidate.id]}</py:when></py:choose> <small py:if="candidate.url"><a href="${candidate.url}">[info]</a></small></td> <py:if test="nextaction=='vote'"> <td><select name="${candidate.id}"> <option py:for="option in range(0,len(candidates)+1)" value="$option">$option</option>
commit 1f0a6d5d78b3239d6c7f338099464e52112f7882 Author: Nigel Jones dev@nigelj.com Date: Tue Oct 7 18:31:56 2008 +1300
Grab Candidate's name from FAS when election is set to usefas - part 1
diff --git a/elections/admin.py b/elections/admin.py index 4708472..3b04273 100644 --- a/elections/admin.py +++ b/elections/admin.py @@ -63,7 +63,7 @@ class Admin(controllers.Controller): if "usefas" not in kw: usefas=0
- 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=nominationend) + 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=nominationend,usefas=usefas) raise turbogears.redirect("/") else: return dict() diff --git a/elections/controllers.py b/elections/controllers.py index fc8fc6e..7ca713b 100644 --- a/elections/controllers.py +++ b/elections/controllers.py @@ -74,10 +74,15 @@ class Root(controllers.RootController):
votergroups = LegalVoters.query.filter_by(election_id=eid).all() candidates = Candidates.query.filter_by(election_id=eid).order_by(Candidates.name).all() + usernamemap = {} + + if election.usefas: + for c in candidates: + usernamemap[c.id] = self.fas.person_by_username(c.name)['human_name']
curtime = datetime.utcnow()
- return dict(eid=eid, candidates=candidates, election=election, curtime=curtime, votergroups=votergroups, appTitle=self.appTitle) + return dict(eid=eid, candidates=candidates, usernamemap=usernamemap, election=election, curtime=curtime, votergroups=votergroups, appTitle=self.appTitle)
@expose(template="elections.templates.results") def results(self,eid=None): diff --git a/elections/templates/about.html b/elections/templates/about.html index 00646cc..d9fcc0c 100644 --- a/elections/templates/about.html +++ b/elections/templates/about.html @@ -12,7 +12,7 @@ <p py:if="election.url"><a href="${election.url}">[More Information]</a></p> <table border="1" cellpadding="1"> <tr py:for="candidate in candidates"> - <td>${candidate.name} <small py:if="candidate.url"><a href="${candidate.url}">[info]</a></small></td> + <td><py:choose test="election.usefas"><py:when test="0">${candidate.name}</py:when><py:when test="1">${usernamemap[candidate.id]}</py:when></py:choose> <small py:if="candidate.url"><a href="${candidate.url}">[info]</a></small></td> </tr> <!-- !This link is okay, but one should appear if the election has public results --> <tr> diff --git a/elections/templates/admnewe.html b/elections/templates/admnewe.html index 063ecea..b0a676d 100644 --- a/elections/templates/admnewe.html +++ b/elections/templates/admnewe.html @@ -19,7 +19,7 @@ <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>Use FAS?</td><td><input type="text" name="usefas" /> </td></tr> + <tr><td>Use FAS?</td><td><input type="checkbox" name="usefas" /> </td></tr> <tr><td></td><td><input type="submit" name="submit" value="Submit" /></td></tr> </table> </form> diff --git a/elections/vote.py b/elections/vote.py index ef687c3..ebd4bc3 100644 --- a/elections/vote.py +++ b/elections/vote.py @@ -76,6 +76,13 @@ class Vote(controllers.Controller):
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() + + usernamemap = {} + + if election.usefas: + for c in candidates: + usernamemap[c.id] = self.fas.person_by_username(c.name)['human_name'] + uvotes = {} next_action = ""
@@ -138,5 +145,5 @@ class Vote(controllers.Controller): uvotes[c.id] = "" next_action = "vote"
- return dict(eid=eid, candidates=candidates, election=election, nextaction=next_action, voteinfo=uvotes, appTitle=self.appTitle) + return dict(eid=eid, candidates=candidates, usernamemap=usernamemap, election=election, nextaction=next_action, voteinfo=uvotes, appTitle=self.appTitle)
commit efbb4454006721ac2c3dea2d859d8ba57cb78c00 Author: Nigel Jones dev@nigelj.com Date: Tue Oct 7 18:18:31 2008 +1300
Import FAS correctly
diff --git a/elections/admin.py b/elections/admin.py index 346b157..4708472 100644 --- a/elections/admin.py +++ b/elections/admin.py @@ -36,7 +36,8 @@ import sqlalchemy from turbogears.database import session
class Admin(controllers.Controller): - def __init__(self, appTitle): + def __init__(self, fas, appTitle): + self.fas = fas self.appTitle = appTitle
#@expose(template='elections.templates.adminlist') diff --git a/elections/controllers.py b/elections/controllers.py index 5de5a4c..fc8fc6e 100644 --- a/elections/controllers.py +++ b/elections/controllers.py @@ -42,8 +42,13 @@ import re class Root(controllers.RootController): appTitle = 'Fedora Elections'
- admin = Admin(appTitle) - vote = Vote(appTitle) + baseURL = config.get('fas.url', 'https://admin.fedoraproject.org/accounts/') + username = config.get('fas.username', 'admin') + password = config.get('fas.password', 'admin') + fas = AccountSystem(baseURL, username=username, password=password) + + admin = Admin(fas, appTitle) + vote = Vote(fas, appTitle)
@expose(template="elections.templates.index") diff --git a/elections/vote.py b/elections/vote.py index 96ee0d2..ef687c3 100644 --- a/elections/vote.py +++ b/elections/vote.py @@ -38,7 +38,8 @@ from turbogears.database import session from datetime import datetime
class Vote(controllers.Controller): - def __init__(self, appTitle): + def __init__(self, fas, appTitle): + self.fas = fas self.appTitle = appTitle
#TODO: This function will be split off into: default => submit => confirm functions, hopefully it was simplify everything
elections-devel@lists.stg.fedorahosted.org