Skip to content

Commit 562a550

Browse files
committed
Add view for second phase voting
1 parent ed4baf1 commit 562a550

4 files changed

Lines changed: 138 additions & 2 deletions

File tree

junction/proposals/dashboard.py

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
from junction.base.constants import (
2020
ProposalReviewVote,
2121
ProposalStatus,
22-
ProposalVotesFilter
22+
ProposalVotesFilter,
23+
ProposalReviewStatus,
2324
)
2425
from junction.conferences.models import Conference, ConferenceProposalReviewer
2526

@@ -263,6 +264,82 @@ def reviewer_votes_dashboard(request, conference_slug):
263264
'form': form})
264265

265266

267+
@require_http_methods(['GET', 'POST'])
268+
def second_phase_voting(request, conference_slug):
269+
conference = get_object_or_404(Conference, slug=conference_slug)
270+
271+
if not is_conference_moderator(user=request.user, conference=conference):
272+
raise PermissionDenied
273+
274+
proposal_sections = conference.proposal_sections.all()
275+
proposals_qs = Proposal.objects.select_related(
276+
'proposal_type', 'proposal_section', 'conference', 'author',
277+
).filter(
278+
conference=conference,
279+
review_status=ProposalReviewStatus.SELECTED
280+
)
281+
282+
proposals = []
283+
s_items = collections.namedtuple('section_items', 'section proposals')
284+
form = ProposalVotesFilterForm(conference=conference)
285+
286+
if request.method == 'GET':
287+
for section in proposal_sections:
288+
section_proposals = [
289+
p for p in proposals_qs if p.proposal_section == section]
290+
proposals.append(s_items(section, section_proposals))
291+
292+
return render(request, 'proposals/second_phase_voting.html',
293+
{'conference': conference,
294+
'proposals': proposals,
295+
'form': form})
296+
297+
form = ProposalVotesFilterForm(conference=conference, data=request.POST)
298+
299+
if not form.is_valid():
300+
return render(request, 'proposals/votes-dashboard.html',
301+
{'form': form,
302+
'conference': conference,
303+
'errors': form.errors})
304+
305+
# Valid form
306+
cps = form.cleaned_data['proposal_section']
307+
cpt = form.cleaned_data['proposal_type']
308+
votes = form.cleaned_data['votes']
309+
review_status = form.cleaned_data['review_status']
310+
proposal_sections = conference.proposal_sections.all()
311+
312+
if cps != 'all':
313+
proposal_sections = ProposalSection.objects.filter(pk=cps)
314+
if cpt != 'all':
315+
proposals_qs = proposals_qs.filter(proposal_type__id__in=cpt)
316+
if votes != 'all':
317+
votes = int(votes)
318+
if review_status != 'all':
319+
proposals_qs = proposals_qs.filter(review_status=review_status)
320+
321+
if votes == ProposalVotesFilter.NO_VOTES:
322+
proposals_qs = [
323+
p for p in proposals_qs if p.get_reviewer_votes_count() == votes]
324+
elif votes == ProposalVotesFilter.MIN_ONE_VOTE:
325+
proposals_qs = [
326+
p for p in proposals_qs if p.get_reviewer_votes_count() >= votes]
327+
elif votes == ProposalVotesFilter.SORT:
328+
proposals_qs = sorted(
329+
proposals_qs, key=lambda x: x.get_reviewer_votes_sum(),
330+
reverse=True)
331+
332+
for section in proposal_sections:
333+
section_proposals = [
334+
p for p in proposals_qs if p.proposal_section == section]
335+
proposals.append(s_items(section, section_proposals))
336+
337+
return render(request, 'proposals/second_phase_voting.html',
338+
{'conference': conference,
339+
'proposals': proposals,
340+
'form': form})
341+
342+
266343
@require_http_methods(['GET', 'POST'])
267344
def export_reviewer_votes(request, conference_slug):
268345
"""

junction/proposals/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Third Party Stuff
55
from django.conf.urls import include, patterns, url
66

7-
from . import comments_views, views, votes_views
7+
from . import comments_views, views, votes_views, dashboard
88

99
comment_urls = patterns(
1010
'',
@@ -22,6 +22,7 @@
2222
url(r'^$', views.list_proposals, name='proposals-list'),
2323
url(r'^create/$', views.create_proposal, name='proposal-create'),
2424
url(r'^to_review/$', views.proposals_to_review, name='proposals-to-review'),
25+
url(r'^second_phase_voting/$', dashboard.second_phase_voting, name='second-phase-voting'),
2526
url(r'^(?P<slug>[\w-]+)/$', views.detail_proposal, name='proposal-detail'),
2627
url(r'^(?P<slug>[\w-]+)~(?P<hashid>.*)/$', views.detail_proposal, name='proposal-detail'),
2728
url(r'^(?P<slug>[\w-]+)/delete/$', views.delete_proposal, name='proposal-delete'),

junction/templates/proposals/list.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<p class="text-left">{{ conference.description|markdown }}</p>
5555
{% if is_reviewer %}
5656
<a class='btn btn-primary' href="{% url 'proposals-to-review' conference.slug %}">Proposals To Review</a>
57+
<a class='btn btn-primary' href="{% url 'second-phase-voting' conference.slug %}">Second Phase Voting</a>
5758
{% endif %}
5859
{% if user.is_superuser or user.is_stuff %}
5960
<a class='btn btn-primary' href="{% url 'proposal-reviewer-votes-dashboard' conference.slug %}">
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{% extends 'base.html' %}
2+
{% load bootstrap3 %}
3+
4+
{% load django_markdown %}
5+
{% load static from staticfiles %}
6+
{% load django_bootstrap_breadcrumbs %}
7+
8+
{% block head_title %} {{ conference.name }} Second phase voting {% endblock %}
9+
{% block og_title %} {{ conference.name }} Second phase voting {% endblock %}
10+
{% block og_description %} {{ conference.description|markdown|safe|striptags}} {% endblock %}
11+
{% block page_description %} {{ conference.description|markdown|safe|striptags}} {% endblock %}
12+
13+
{% block endhead %}
14+
<!-- Custom CSS -->
15+
<link href="{% static 'css/list.css' %}" rel="stylesheet">
16+
{% endblock %}
17+
18+
{% block breadcrumbs %}
19+
{{ block.super }}
20+
{% breadcrumb conference.name "conference-detail" conference.slug %}
21+
{% breadcrumb "Second phase voting" "proposals-to-review" conference.slug %}
22+
{% endblock %}
23+
24+
{% block navbar_logo %}
25+
{% if conference.logo %}
26+
<a href="{% url "conference-detail" conference.slug %}">
27+
<img src="{{ conference.logo.url }}">
28+
</a>
29+
{% else %}
30+
<a href="#" class="navbar-brand">{{ conference.name }}</a>
31+
{% endif %}
32+
{% endblock navbar_logo %}
33+
34+
{% block page_classes %}{{ block.super}} page-proposals{% endblock page_classes %}
35+
36+
{% block content %}
37+
<section class="content custom-container proposal-list">
38+
<div class="push-4-bottom push-1-top">
39+
<a name="proposals"></a>
40+
{% if proposals %}
41+
<h2>Second Phase Voting</h2>
42+
<hr>
43+
44+
<div id="#proposals">
45+
{% for section_items in proposals %}
46+
{% if section_items.proposals %}
47+
{% include 'proposals/partials/proposal-list--review-items.html' with proposals=section_items.proposals title=section_items.section display_status=False %}
48+
{% endif %}
49+
{% endfor %}
50+
</div>
51+
52+
{% else %}
53+
<p>No proposals to vote.</p>
54+
{% endif %}
55+
</div>
56+
</section>
57+
{% endblock %}

0 commit comments

Comments
 (0)