Skip to content
Snippets Groups Projects
Commit 81d4b6e2 authored by Ben Adida's avatar Ben Adida
Browse files

made elections-voted more presentable

parent b7ea1982
Branches
Tags
No related merge requests found
......@@ -185,8 +185,17 @@ class Election(HeliosModel):
return query
@classmethod
def get_by_user_as_voter(cls, user):
return [v.election for v in Voter.get_by_user(user)]
def get_by_user_as_voter(cls, user, archived_p=None, limit=None):
query = cls.objects.filter(voter__user = user)
if archived_p == True:
query = query.exclude(archived_at= None)
if archived_p == False:
query = query.filter(archived_at= None)
query = query.order_by('-created_at')
if limit:
return query[:limit]
else:
return query
@classmethod
def get_by_uuid(cls, uuid):
......
{% extends TEMPLATE_BASE %}
{% block content %}
<h2 class="title">Elections where you voted <span style="font-size:0.7em;">[<a href="/">back to home</a>]</span></h2>
<ul>
{% for election in elections %}
<li> <a href="{% url helios.views.one_election_view election.uuid %}">{{election.name}}</a></li>
{% endfor %}
</ul>
{% endblock %}
......@@ -31,6 +31,7 @@ urlpatterns = patterns('',
(r'^elections/single_ballot_verifier$', election_single_ballot_verifier),
(r'^elections/new$', election_new),
(r'^elections/administered$', elections_administered),
(r'^elections/voted$', elections_voted),
(r'^elections/(?P<election_uuid>[^/]+)', include('helios.election_urls')),
......
......@@ -160,6 +160,13 @@ def elections_administered(request):
return render_template(request, "elections_administered", {'elections': elections})
@login_required
def elections_voted(request):
user = get_user(request)
elections = Election.get_by_user_as_voter(user)
return render_template(request, "elections_voted", {'elections': elections})
@login_required
def election_new(request):
......
......@@ -39,6 +39,7 @@
{% else %}
<em>none yet</em>
{% endif %}
<p>[<a href="{% url helios.views.elections_voted %}">see all</a>]</p>
{% else %}
<h3>Log In to Start Voting</h3>
{{login_box|safe}}
......
......@@ -36,7 +36,7 @@ def home(request):
elections_administered = None
if user:
elections_voted = Election.get_by_user_as_voter(user)
elections_voted = Election.get_by_user_as_voter(user, limit=5)
else:
elections_voted = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment