Skip to content

Commit

Permalink
fixed bug no more reclose or restart of elections
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Feb 28, 2014
1 parent 2b7f603 commit 330ed3d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions controllers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ def edit():
@auth.requires(auth.user and auth.user.is_manager)
def start():
election = db.election(request.args(0,cast=int)) or redirect(URL('index'))
check_closed(election)
response.subtitle = election.title+T(' / Start')
demo = ballot2form(election.ballot_model)
return dict(demo=demo,election=election)

@auth.requires(auth.user and auth.user.is_manager)
def start_callback():
election = db.election(request.args(0,cast=int)) or redirect(URL('index'))
check_closed(election)
form = SQLFORM.factory(
submit_button=T('Email Voters and Start Election Now!'))
form.element(_type='submit').add_class('btn')
Expand Down Expand Up @@ -259,11 +261,18 @@ def email_voter_and_managers(election,voter,ballot,message):
sender=sender, reply_to=sender)
return ret

def check_closed(election):
if election.closed:
session.flash = T('Election already closed')
redirect(URL('elections'))


@auth.requires(auth.user and auth.user.is_manager)
def close_election():
import zipfile, os
election = db.election(request.args(0,cast=int)) or \
redirect(URL('invalid_link'))
check_closed(election)
response.subtitle = election.title
dialog = FORM.confirm(T('Close'),
{T('Cancel'):URL('elections')})
Expand Down Expand Up @@ -307,6 +316,7 @@ def close_election():
orderby=db.ballot.ballot_uuid)
archive.writestr('ballots.csv',str(ballots))
archive.close()
election.update_record(closed=True)
session.flash = 'Election Closed!'
redirect(URL('results',args=election.id))
return dict(dialog=dialog,election=election)
Expand Down
1 change: 1 addition & 0 deletions models/db_votes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Field('public_key',writable=False,readable=False),
Field('private_key',writable=False,readable=False),
Field('counters','text',writable=False,readable=False),
Field('closed','boolean',writable=False,readable=False),
auth.signature,
format='%(title)s')

Expand Down
4 changes: 3 additions & 1 deletion views/default/elections.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ <h2>Elections managed by you</h2>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
{{if not row.closed:}}
{{=LI(A(I(_class='icon-edit'),' ',T('Edit Election'),_href=URL('edit',args=row.id)))}}
{{=LI(A(I(_class='icon-play-circle'),' ',T('Start Election'),_href=URL('start',args=row.id)))}}
{{=LI(A(I(_class='icon-envelope'),' ',T('Send Reminder'),_href=URL('reminders',args=row.id)))}}
{{=LI(A(I(_class='icon-off'),' ',T('Close Election'),_href=URL('close_election',args=row.id)))}}
{{pass}}
{{=LI(A(I(_class='icon-folder-open'),' ',T('Ballots'),_href=URL('ballots',args=row.id)))}}
{{=LI(A(I(_class='icon-list'),' ',T('Results'),_href=URL('results',args=row.id)))}}
{{=LI(A(I(_class='icon-download'),' ',T('CSV Voters'),_href=URL('voters_csv.csv',args=row.id)))}}
{{=LI(A(I(_class='icon-edit'),' ',T('Edit Election'),_href=URL('edit',args=row.id)))}}
</ul>
</div>
</td>
Expand Down

0 comments on commit 330ed3d

Please sign in to comment.