Skip to content

Commit

Permalink
added ability to archive an election
Browse files Browse the repository at this point in the history
  • Loading branch information
benadida committed Aug 25, 2008
1 parent e949881 commit 6acd27c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 8 deletions.
16 changes: 16 additions & 0 deletions controllers/election.py
Expand Up @@ -11,6 +11,8 @@

import cherrypy, time, logging

import datetime

try:
from django.utils import simplejson
except:
Expand Down Expand Up @@ -265,6 +267,20 @@ def set_reg(self, election, open_p=False):
election.save()
self.redirect("./voters_manage")

@web
@session.login_protect
def archive(self, election, archive_p=True):
"""
archive an election
"""
user, election = self.check(election)
if bool(int(archive_p)):
election.archived_at = datetime.datetime.utcnow()
else:
election.archived_at = None
election.save()
self.redirect("./view")

@web
@json
def result(self, election, **kw):
Expand Down
4 changes: 2 additions & 2 deletions controllers/user.py
Expand Up @@ -31,14 +31,14 @@ class UserController(Controller):
TEMPLATES_DIR = basic.HeliosController.TEMPLATES_DIR + 'user/'

@web
def index(self):
def index(self, include_archived=False):
"""
Display user homepage.
"""
user = self.user()

if user:
elections = do.Election.getByAdmin(user)
elections = do.Election.getByAdmin(user, include_archived)
status = session.get_status()
return self.render('index')
else:
Expand Down
4 changes: 2 additions & 2 deletions index.yaml
Expand Up @@ -10,7 +10,7 @@ indexes:
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.

# Used 11 times in query history.
# Unused in query history -- copied from input.
- kind: ElectionExponent
properties:
- name: election
Expand All @@ -30,7 +30,7 @@ indexes:
- name: cast_id
direction: desc

# Used 2 times in query history.
# Unused in query history -- copied from input.
- kind: Voter
properties:
- name: election
Expand Down
1 change: 1 addition & 0 deletions models/modelsGAE.py
Expand Up @@ -39,6 +39,7 @@ class Election(mbase.ElectionBase):
frozen_at = db.DateTimeProperty(auto_now_add=False)
voting_starts_at = db.DateTimeProperty(auto_now_add=False)
voting_ends_at = db.DateTimeProperty(auto_now_add=False)
archived_at = db.DateTimeProperty(auto_now_add=False, default=None)

# encrypted tally, each a JSON string
# used only for homomorphic tallies
Expand Down
2 changes: 1 addition & 1 deletion models/modelsStandalone.py
Expand Up @@ -22,7 +22,7 @@ class Election(mbase.ElectionBase):
SEQ_NAME = 'election_id_seq'
FIELDS = ['election_id','admin_user_id','election_type','name','election_hash','questions_json','public_key_json','private_key_json',
'election_frozen_at','voting_starts_at','voting_ends_at','openreg_enabled','encrypted_tally','running_tally','decryption_proof',
'result_json']
'result_json', 'archived_at']

# when JSON'ified
JSON_FIELDS = mbase.ElectionBase.JSON_FIELDS
Expand Down
4 changes: 3 additions & 1 deletion models/modelsbase.py
Expand Up @@ -278,8 +278,10 @@ def decrypt(self):
self.save()

@classmethod
def getByAdmin(cls, user):
def getByAdmin(cls, user, include_archived = False):
query = cls.all().filter('admin = ', user)
if not include_archived:
query.filter('archived_at = ', None)
return [r for r in query]

class ElectionExponentBase(DBObject):
Expand Down
2 changes: 1 addition & 1 deletion static/main.css
Expand Up @@ -44,7 +44,7 @@ body {
}

#footer a, #footer a:visited {
color: #ff9;
color: black;
text-decoration: none;
}

Expand Down
5 changes: 5 additions & 0 deletions templates/election/one.tmpl
Expand Up @@ -44,6 +44,11 @@
<br /><li> <a href="email_voters">email voters</a></li>
#end if

#if not $election.archived_at
<br /><li> <a href="archive">archive election</a></li>
#else
<br /><br /><em>election archived</em> [<a href="./archive?archive_p=0">un-archive</a>]
#end if
</ul>
</div>
#end if
Expand Down
8 changes: 7 additions & 1 deletion templates/user/index.tmpl
Expand Up @@ -6,7 +6,13 @@
[<a href="logout">Log out</a>]
</p>

<h3>Elections you Manage</h3>
<h3>Elections you Manage
#if $include_archived
<span style="font-size: 12pt;">[<a href="./">exclude archived</a>]</span>
#else
<span style="font-size: 12pt;">[<a href="./?include_archived=1">include archived</a>]</span>
#end if
</h3>
<ul>
#for $e in $elections
<li> <a href="/elections/$e.key/view">$e.name</a></li>
Expand Down

0 comments on commit 6acd27c

Please sign in to comment.