|
19 | 19 | from junction.base.constants import ( |
20 | 20 | ProposalReviewVote, |
21 | 21 | ProposalStatus, |
22 | | - ProposalVotesFilter |
| 22 | + ProposalVotesFilter, |
| 23 | + ProposalReviewStatus, |
23 | 24 | ) |
24 | 25 | from junction.conferences.models import Conference, ConferenceProposalReviewer |
25 | 26 |
|
@@ -263,6 +264,82 @@ def reviewer_votes_dashboard(request, conference_slug): |
263 | 264 | 'form': form}) |
264 | 265 |
|
265 | 266 |
|
| 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 | + |
266 | 343 | @require_http_methods(['GET', 'POST']) |
267 | 344 | def export_reviewer_votes(request, conference_slug): |
268 | 345 | """ |
|
0 commit comments