Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Bug933375 - Only show current and future votes on the first vote listing page #896

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
127 changes: 127 additions & 0 deletions remo/voting/templates/list_past_votings.html
@@ -0,0 +1,127 @@
{% extends "base_fd4.html" %}
{% block pagetitle %}Mozilla Reps - Voting{% endblock %}

{% block content %}
<main role="main" class="voting-main">
<div class="row">
<div class="large-10 columns">
<h1>Past Voting</h1>
</div>
{% if user.has_perm('voting.add_poll') %}
<div class="large-2 columns align-right">
<a href="{{ url('voting_new_voting') }}"
class="button small update" role="button"
id="voting-create-button">Create voting</a>
</div>
{% endif %}
</div>

{% macro display_polls(polls, show_pagination) -%}
<div class="large-12 columns">
<table class="dashboard-table responsive">
<thead>
<tr>
<th class="dashboard-clickable type-string">Name</th>
<th class="dashboard-clickable type-string">Start Date</th>
<th class="dashboard-clickable type-string">End Date</th>
<th class="dashboard-clickable type-string">Eligible Groups</th>
<th class="dashboard-clickable type-string align-center">Users Voted</th>
<th class="dashboard-clickable type-string align-center">Voting Progress</th>
</tr>
</thead>
<tbody>
{% for poll in polls %}
<tr>
<td>
<a href="{{ url('voting_view_voting', slug=poll.slug) }}">
{{ poll.name }}
</a>
</td>
<td title="{{ poll.start|format_datetime }}"
data-time="{{ poll.start|format_datetime_iso }}">
{{ poll.start|format_datetime }}
</td>
<td title="{{ poll.end|format_datetime }}"
data-time="{{ poll.end|format_datetime_iso }}">
{{ poll.end|format_datetime }}
</td>
<td>{{ poll.valid_groups }}</td>
<td class="align-center">{{ poll|get_users_voted }}</td>
<td>
<span class="meter_text">{{ poll|get_meter_value }}%</span>
<meter min="0" optimum="85" value="{{ poll|get_meter_value }}" max="100" high="80">
<div class="progressbar">
<span class="progressspan" data-percent="{{ poll|get_meter_value }}"></span>
</div>
</meter>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if show_pagination %}
<div class="row">
<div class="large-12 columns" id="voting-pagination">
{% if polls.has_previous() %}
<a class="prev" title="Previous Page" data-tooltip
href="{{ '#'|urlparams(page=polls.previous_page_number()) }}">
&laquo;
</a>
{% endif %}
<label for="page-select">Page: </label>
<select id="page-select" autocomplete="off">
{% for i in range(1, polls.paginator.num_pages + 1) %}
<option {% if i == polls.number %} selected {% endif %}
value="{{ '#'|urlparams(page=i) }}">
{{ i }}
</option>
{% endfor %}
</select>
{% if polls.has_next() %}
<a class="next" title="Next Page" data-tooltip
href="{{ '#'|urlparams(page=polls.next_page_number()) }}">
&raquo;
</a>
{% endif %}
</div>
</div>
{% endif %}
</div>
{%- endmacro%}

<div class="row">
<div class="large-12 columns">

<!-- Past votes block -->
<div class="dashboard-box">
<div class="row">
<div class="large-12 columns">
<h2>Past Votes</h2>
</div>
</div>

<div class="row">
{% if past_polls %}
{{ display_polls(past_polls, show_pagination=True) }}
{% else %}
<div class="large-12 columns no-bugs">
<p>No past votes found!</p>
</div>
{% endif %}
<div class="align-right">
<a href="/voting">Show current</a>
</div>
</div>
</div>
<!-- end Past votes block -->
</div>
</div>
</main>
{% endblock %}

{% block bottomextra %}
{% compress js %}
<script src="{{ static('base/js/stupidtable.js') }}"></script>
<script src="{{ static('voting/js/voting_list.js') }}"></script>
{% endcompress %}
{% endblock %}
12 changes: 4 additions & 8 deletions remo/voting/templates/list_votings.html
Expand Up @@ -184,18 +184,14 @@ <h2>Future Votes</h2>
<div class="dashboard-box">
<div class="row">
<div class="large-12 columns">
<h2>Past Votes</h2>
<h2>{{ past_polls|count }} Past Votes</h2>
</div>
</div>

<div class="row">
{% if past_polls %}
{{ display_polls(past_polls, show_pagination=True) }}
{% else %}
<div class="large-12 columns no-bugs">
<p>No past votes found!</p>
</div>
{% endif %}
<div class="large-12 columns align-center">
<a href="past_votings">Show past votes</a>
</div>
</div>
</div>
<!-- end Past votes block -->
Expand Down
24 changes: 19 additions & 5 deletions remo/voting/views.py
Expand Up @@ -25,10 +25,26 @@ def list_votings(request):
if not user.groups.filter(name='Admin').exists():
polls = Poll.objects.filter(valid_groups__in=user.groups.all())

past_polls_query = polls.filter(end__lt=now())
past_polls = polls.filter(end__lt=now())
current_polls = polls.filter(start__lt=now(), end__gt=now())
future_polls = polls.filter(start__gt=now())

return render(request, 'list_votings.html',
{'user': user,
'past_polls':past_polls,
'current_polls': current_polls,
'future_polls': future_polls})

@permission_check()
def list_votings_past(request):
"""List votings view."""
user = request.user
polls = Poll.objects.all()
if not user.groups.filter(name='Admin').exists():
polls = Poll.objects.filter(valid_groups__in=user.groups.all())

past_polls_query = polls.filter(end__lt=now())

past_polls_paginator = Paginator(past_polls_query, settings.ITEMS_PER_PAGE)
past_polls_page = request.GET.get('page', 1)

Expand All @@ -39,11 +55,9 @@ def list_votings(request):
except EmptyPage:
past_polls = past_polls_paginator.page(past_polls_paginator.num_pages)

return render(request, 'list_votings.html',
return render(request, 'list_past_votings.html',
{'user': user,
'past_polls': past_polls,
'current_polls': current_polls,
'future_polls': future_polls})
'past_polls': past_polls})


@permission_check(permissions=['voting.add_poll', 'voting.change_poll'])
Expand Down
1 change: 1 addition & 0 deletions remo/voting/voting_urls.py
Expand Up @@ -3,5 +3,6 @@
urlpatterns = patterns(
'remo.voting.views',
url(r'^$', 'list_votings', name='voting_list_votings'),
url(r'^past_votings$', 'list_votings_past', name='voting_list_votings_past'),
url(r'^new/$', 'edit_voting', name='voting_new_voting'),
)