Skip to content

Commit 7c3241a

Browse files
authored
Merge pull request #490 from ChillarAnand/dash
Add sort by reviewer votes in votes dashboard
2 parents 55d80a6 + 51dc483 commit 7c3241a

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

junction/base/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ class ProposalReviewerComment:
8080
class ProposalVotesFilter:
8181
_NO_VOTES = [0, "No votes"]
8282
_MIN_ONE_VOTE = [1, "Minimum 1 vote"]
83-
_SORT = [2, "Sort by vote value"]
83+
_SORT_BY_SUM = [2, "Sort by total votes"]
84+
_SORT_BY_REVIEWER = [3, "Sort by your votes"]
8485

8586

8687
class ConferenceSettingConstants:

junction/proposals/dashboard.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,22 @@ def reviewer_votes_dashboard(request, conference_slug):
247247
elif votes == ProposalVotesFilter.MIN_ONE_VOTE:
248248
proposals_qs = [
249249
p for p in proposals_qs if p.get_reviewer_votes_count() >= votes]
250-
elif votes == ProposalVotesFilter.SORT:
250+
elif votes == ProposalVotesFilter.SORT_BY_REVIEWER:
251+
proposals_qs = sorted(
252+
proposals_qs,
253+
key=lambda x: x.get_reviewer_vote_value(reviewer=request.user),
254+
reverse=True,
255+
)
256+
elif votes == ProposalVotesFilter.SORT_BY_SUM:
251257
proposals_qs = sorted(
252258
proposals_qs, key=lambda x: x.get_reviewer_votes_sum(),
253259
reverse=True)
260+
proposals = [s_items('', proposals_qs)]
254261

255-
for section in proposal_sections:
256-
section_proposals = [
257-
p for p in proposals_qs if p.proposal_section == section]
258-
proposals.append(s_items(section, section_proposals))
262+
if votes != ProposalVotesFilter.SORT_BY_SUM:
263+
for section in proposal_sections:
264+
section_proposals = [p for p in proposals_qs if p.proposal_section == section]
265+
proposals.append(s_items(section, section_proposals))
259266

260267
return render(request, 'proposals/votes-dashboard.html',
261268
{'conference': conference,

junction/proposals/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ def get_reviewer_votes_sum(self):
187187
sum_of_votes = sum((v.vote_value.vote_value for v in votes))
188188
return sum_of_votes
189189

190+
def get_reviewer_vote_value(self, reviewer):
191+
try:
192+
vote = ProposalSectionReviewerVote.objects.get(
193+
proposal=self, voter__conference_reviewer__reviewer=reviewer,
194+
)
195+
return vote.vote_value.vote_value
196+
except ProposalSectionReviewerVote.DoesNotExist:
197+
return 0
198+
190199
def get_reviewers_count(self):
191200
""" Count of reviewers for given proposal section """
192201
return ProposalSectionReviewer.objects.filter(

junction/templates/proposals/votes-dashboard.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ <h2>Proposal Votes Dashboard</h2>
3030
{% csrf_token %}
3131
{% bootstrap_form form %}
3232
<br /><br />
33-
</form>
34-
{% buttons %}
33+
{% buttons %}
3534
<span class="pull-right"></span>
3635
<div class="col-sm-offset-5 col-sm-2 text-center">
3736
<button type="submit" class="btn btn-primary">
3837
Submit
3938
</button>
4039
</div>
41-
{% endbuttons %}
40+
{% endbuttons %}
41+
</form>
4242
</div>
4343
<br />
44+
<hr>
4445
<div id="#proposals" class="row">
4546
{% for section_items in proposals %}
4647
{% if section_items.proposals %}

0 commit comments

Comments
 (0)