|
| 1 | +import collections |
| 2 | + |
1 | 3 | from django.core.exceptions import PermissionDenied |
2 | 4 |
|
3 | | -from junction.base.constants import PSRVotePhase, ProposalCommentType |
| 5 | +from junction.base.constants import PSRVotePhase, ProposalCommentType, \ |
| 6 | + ProposalReviewVote, ProposalVotesFilter |
4 | 7 | from junction.proposals import permissions |
5 | | -from junction.proposals.models import ProposalComment, ProposalSectionReviewer, \ |
6 | | - ProposalSectionReviewerVote, ProposalSectionReviewerVoteValue |
| 8 | +from junction.proposals.models import ProposalComment, ProposalSection, \ |
| 9 | + ProposalSectionReviewer, ProposalSectionReviewerVote, \ |
| 10 | + ProposalSectionReviewerVoteValue |
7 | 11 |
|
8 | 12 |
|
9 | 13 | def get_reviewer_vote_info(user, conference, proposal, vote_phase): |
@@ -67,3 +71,81 @@ def update_reviewer_vote_info(user, psr_vote, vote_value, comment, phase, propos |
67 | 71 | ) |
68 | 72 |
|
69 | 73 | return psr_vote, p_comment |
| 74 | + |
| 75 | + |
| 76 | +def _sort_proposals_for_dashboard(conference, proposals_qs, user, form): |
| 77 | + """ |
| 78 | + """ |
| 79 | + cps = form.cleaned_data['proposal_section'] |
| 80 | + cpt = form.cleaned_data['proposal_type'] |
| 81 | + votes = form.cleaned_data['votes'] |
| 82 | + review_status = form.cleaned_data['review_status'] |
| 83 | + |
| 84 | + proposal_sections = conference.proposal_sections.all() |
| 85 | + s_items = collections.namedtuple('section_items', 'section proposals') |
| 86 | + proposals = [] |
| 87 | + |
| 88 | + if cps != 'all': |
| 89 | + proposal_sections = ProposalSection.objects.filter(pk=cps) |
| 90 | + if cpt != 'all': |
| 91 | + proposals_qs = proposals_qs.filter(proposal_type__id__in=cpt) |
| 92 | + if votes != 'all': |
| 93 | + votes = int(votes) |
| 94 | + if review_status != 'all': |
| 95 | + proposals_qs = proposals_qs.filter(review_status=review_status) |
| 96 | + |
| 97 | + if votes == ProposalVotesFilter.NO_VOTES: |
| 98 | + proposals_qs = [ |
| 99 | + p for p in proposals_qs if p.get_reviewer_votes_count() == votes] |
| 100 | + elif votes == ProposalVotesFilter.MIN_ONE_VOTE: |
| 101 | + proposals_qs = [ |
| 102 | + p for p in proposals_qs if p.get_reviewer_votes_count() >= votes] |
| 103 | + elif votes == ProposalVotesFilter.SORT_BY_REVIEWER: |
| 104 | + proposals_qs = sorted( |
| 105 | + proposals_qs, |
| 106 | + key=lambda x: x.get_reviewer_vote_value(reviewer=user), |
| 107 | + reverse=True, |
| 108 | + ) |
| 109 | + elif votes == ProposalVotesFilter.SORT_BY_SUM: |
| 110 | + proposals_qs = sorted( |
| 111 | + proposals_qs, key=lambda x: x.get_reviewer_votes_sum(), |
| 112 | + reverse=True) |
| 113 | + proposals = [s_items('', proposals_qs)] |
| 114 | + |
| 115 | + elif votes == ProposalVotesFilter.SORT_BY_SELECTION: |
| 116 | + # Selection of proposal is based on conference guidelines. |
| 117 | + # More info is available at http://tiny.cc/qzo5cy |
| 118 | + |
| 119 | + proposals_qs = [p for p in proposals_qs if not p.has_negative_votes()] |
| 120 | + proposals_qs = sorted(proposals_qs, key=lambda x: x.get_reviewer_votes_sum(), reverse=True) |
| 121 | + |
| 122 | + selected = [p for p in proposals_qs if p.get_reviewer_votes_count_by_value(ProposalReviewVote.MUST_HAVE) >= 2] |
| 123 | + proposals.append(s_items('Selected', selected)) |
| 124 | + |
| 125 | + batch1 = [p for p in proposals_qs |
| 126 | + if p.get_reviewer_votes_count_by_value(ProposalReviewVote.MUST_HAVE) == 1 and |
| 127 | + p.get_reviewer_votes_count_by_value(ProposalReviewVote.GOOD) > 2] |
| 128 | + proposals.append(s_items('1 Must Have & 2+ Good Votes', batch1)) |
| 129 | + |
| 130 | + batch2 = [p for p in proposals_qs |
| 131 | + if p.get_reviewer_votes_count_by_value(ProposalReviewVote.MUST_HAVE) == 1 and |
| 132 | + p.get_reviewer_votes_count_by_value(ProposalReviewVote.GOOD) == 1] |
| 133 | + proposals.append(s_items('1 Must Have & 1 Good Vote', batch2)) |
| 134 | + |
| 135 | + batch3 = [p for p in proposals_qs |
| 136 | + if p.get_reviewer_votes_count_by_value(ProposalReviewVote.GOOD) > 2 and |
| 137 | + p not in batch1] |
| 138 | + proposals.append(s_items('2+ Good Votes', batch3)) |
| 139 | + |
| 140 | + batch4 = [p for p in proposals_qs |
| 141 | + if p.get_reviewer_votes_count_by_value(ProposalReviewVote.GOOD) == 1 and |
| 142 | + p.get_reviewer_votes_count_by_value(ProposalReviewVote.NOT_BAD) > 2 and |
| 143 | + p not in batch2] |
| 144 | + proposals.append(s_items('1 Good & 2+ Not Bad votes', batch4)) |
| 145 | + |
| 146 | + if votes not in (ProposalVotesFilter.SORT_BY_SUM, ProposalVotesFilter.SORT_BY_SELECTION): |
| 147 | + for section in proposal_sections: |
| 148 | + section_proposals = [p for p in proposals_qs if p.proposal_section == section] |
| 149 | + proposals.append(s_items(section, section_proposals)) |
| 150 | + |
| 151 | + return proposals |
0 commit comments