Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ranking to Recap review Grants #3689

Closed
wants to merge 3 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions backend/reviews/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@

from django import forms
from django.contrib import admin, messages
from django.db.models import Count, F, OuterRef, Prefetch, Subquery, Sum
from django.db.models import (
Count,
F,
OuterRef,
Prefetch,
Subquery,
Sum,
CharField,
Value,
)
from django.db.models.functions import Concat, Cast, Coalesce
from django.http.request import HttpRequest
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.urls import path, reverse
from django.utils.safestring import mark_safe

from django.contrib.postgres.aggregates import StringAgg
from grants.models import Grant
from participants.models import Participant
from reviews.models import AvailableScoreOption, ReviewSession, UserReview
Expand Down Expand Up @@ -292,12 +302,39 @@ def _review_grants_recap_view(self, request, review_session):
F("total_score") / F("vote_count"),
output_field=FloatField(),
),
is_a_speaker=Exists(
has_sent_proposals=Exists(
Submission.objects.non_cancelled().filter(
speaker_id=OuterRef("user_id"),
conference_id=review_session.conference_id,
)
),
ranking=Coalesce(
Subquery(
Submission.objects.filter(
speaker_id=OuterRef("user_id"),
conference_id=OuterRef("conference_id"),
)
.annotate(
ranking=StringAgg(
Concat(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: improve this, if someone has sent more than one submission, so I would separate each submission ...

"rankings__tag__name",
Value(": "),
Cast("rankings__rank", CharField()),
Value("/"),
Cast(
"rankings__total_submissions_per_tag",
CharField(),
),
output_field=CharField(),
),
delimiter=", \n",
)
)
.values("ranking")[:1]
),
Value(""),
output_field=CharField(),
),
user_private_comment=Subquery(
UserReview.objects.filter(
review_session_id=review_session_id,
Expand Down Expand Up @@ -592,7 +629,7 @@ def _render_grant_review(
context = dict(
self.admin_site.each_context(request),
grant=grant,
is_speaker=Submission.objects.non_cancelled()
has_sent_proposals=Submission.objects.non_cancelled()
.filter(
speaker_id=grant.user_id,
conference_id=grant.conference_id,
Expand Down
4 changes: 2 additions & 2 deletions backend/reviews/templates/grant-review.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ <h2>Grant</h2>
</div>

<div class="review-row">
<strong>Is Speaker?</strong>
<div>{{is_speaker|yesno}}</div>
<strong>Has sent proposal(s)?</strong>
<div>{{has_sent_proposals|yesno}}</div>
</div>

<div class="review-row">
Expand Down
19 changes: 16 additions & 3 deletions backend/reviews/templates/grants-recap.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
<div class="text"><span>Votes</span></div>
<div class="clear"></div>
</th>
<th scope="col">
<div class="text"><span>Ranking</span></div>
<div class="clear"></div>
</th>
<th scope="col">
<div class="text"><span>Status</span></div>
<div class="clear"></div>
Expand Down Expand Up @@ -209,8 +213,8 @@
<span>{{item.get_interested_in_volunteering_display}}</span>
</li>
<li>
<strong>Is a speaker?</strong>
<span>{{item.is_a_speaker|yesno}}</span>
<strong>Has sent proposal(s)?</strong>
<span>{{item.has_sent_proposals|yesno}}</span>
</li>
</ul>
</td>
Expand Down Expand Up @@ -240,7 +244,16 @@
<p>{{ item.user_private_comment }}</p>
{% endif %}
</td>

<td>
{% for submission in item.submissions.all %}
{% for ranking in submission.rankings.all %}
{{ ranking.tag.name }}: {{ ranking.rank }} / {{ ranking.total_submissions_per_tag }}<br>
{% endfor %}
{% empty %}
-
<!-- Display nothing or some placeholder if there are no submissions -->
{% endfor %}
</td>
<td>
{{ item.get_status_display }}
</td>
Expand Down
Loading