Skip to content

Commit 3270cc9

Browse files
committed
Implement REVIEW_SCORE_SHOW_TOTAL for review all views, review detail view and Slack messages as well.
1 parent d731a0a commit 3270cc9

9 files changed

Lines changed: 35 additions & 18 deletions

File tree

‎docs/setup/administrators/configuration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Send out e-mail, slack messages etc. from Hypha. Set to true for production.
207207

208208
----
209209

210-
Show the total (sum) of a review's scored answers instead of the average of them, in the "Reviews & assignees" block on the submission detail page. The block's overall score is then the sum of every review's total, rather than the average of their averages.
210+
Show the total (sum) of a review's scored answers instead of the average of them. Affects the "Reviews & assignees" block on the submission detail page, the review detail page and the all-reviews comparison table. The overall score in the "Reviews & assignees" block is then the sum of every review's total, rather than the average of their averages.
211211

212212
REVIEW_SCORE_SHOW_TOTAL = env.bool('REVIEW_SCORE_SHOW_TOTAL', False)
213213

‎hypha/apply/activity/adapters/slack.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class SlackAdapter(AdapterBase):
5858
"<{link}|{source.title_text_display}> by {source.user} has been invited to submit a proposal"
5959
),
6060
MESSAGES.NEW_REVIEW: _(
61-
"{user} has submitted a review for <{link}|{source.title_text_display}>. Outcome: {review.outcome}, Score: {review.get_score_display}"
61+
"{user} has submitted a review for <{link}|{source.title_text_display}>. Outcome: {review.outcome}, Score: {review.score_display}"
6262
),
6363
MESSAGES.READY_FOR_REVIEW: "notify_reviewers",
6464
MESSAGES.OPENED_SEALED: _(

‎hypha/apply/funds/templates/funds/includes/review_sidebar_item.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n review_tags wagtailimages_tags heroicons %}
1+
{% load i18n wagtailimages_tags heroicons %}
22

33
<li
44
class="px-0 py-2 {% if not reviewer.review %}text-base-content/80 {% endif %}"
@@ -49,7 +49,7 @@
4949
{% if reviewer.role %}{% image reviewer.role.icon max-12x12 %}{% endif %}
5050
</div>
5151
{% endif %}
52-
{% with reviewer.review.get_recommendation_display as recommendation and reviewer.review|review_score as score %}
52+
{% with reviewer.review.get_recommendation_display as recommendation and reviewer.review.score_display as score %}
5353
<div class="col-span-1 {{ recommendation|slugify }}">{{ recommendation }}</div>
5454
<div class="col-span-1 {{ recommendation|slugify }}">{{ score }}</div>
5555
{% endwith %}

‎hypha/apply/review/models.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.conf import settings
12
from django.core.serializers.json import DjangoJSONEncoder
23
from django.db import models
34
from django.urls import reverse
@@ -230,7 +231,15 @@ def get_score_display(self):
230231

231232
@property
232233
def get_total_score_display(self):
233-
return "{:.1f}".format(self.total_score) if self.total_score != NA else "-"
234+
# Scores are whole numbers, so their total is one too.
235+
return "{:.0f}".format(self.total_score) if self.total_score != NA else "-"
236+
237+
@property
238+
def score_display(self):
239+
"""The score to show in the UI, set with REVIEW_SCORE_SHOW_TOTAL."""
240+
if settings.REVIEW_SCORE_SHOW_TOTAL:
241+
return self.get_total_score_display
242+
return self.get_score_display
234243

235244
def get_absolute_url(self):
236245
return reverse(

‎hypha/apply/review/templates/review/review_detail.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</div>
4343
<div>
4444
<dt class="mb-2 font-bold">{% trans "Score" %}</dt>
45-
<dd><p class="badge badge-outline">{{ review.get_score_display }}</p></dd>
45+
<dd><p class="badge badge-outline">{{ review.score_display }}</p></dd>
4646
</div>
4747
<div>
4848
<dt class="mb-2 font-bold">{% trans "Visibility" %}</dt>

‎hypha/apply/review/templatetags/review_tags.py‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ def has_draft(user, submission):
5151
)
5252

5353

54-
@register.filter
55-
def review_score(review):
56-
"""The score of a single review, as shown in the reviews sidebar."""
57-
if settings.REVIEW_SCORE_SHOW_TOTAL:
58-
return review.get_total_score_display
59-
return review.get_score_display
60-
61-
6254
@register.filter
6355
def reviews_score(reviewers):
6456
"""The combined score of the submitted reviews, for the reviews sidebar.
@@ -80,7 +72,7 @@ def reviews_score(reviewers):
8072
if settings.REVIEW_SCORE_SHOW_TOTAL:
8173
totals = [review.total_score for review in reviews if review.total_score != NA]
8274
if totals:
83-
return _("Total score: {total}").format(total=sum(totals))
75+
return _("Total score: {total}").format(total="{:.0f}".format(sum(totals)))
8476
return ""
8577

8678
scores = [review.score for review in reviews if review.score != NA]

‎hypha/apply/review/tests/test_models.py‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.test import TestCase
1+
from django.test import TestCase, override_settings
22

33
from hypha.apply.funds.tests.factories import ApplicationSubmissionFactory
44

@@ -100,3 +100,19 @@ def test_na_answers_score_zero(self):
100100
field = review.score_fields[0]
101101
review.form_data[field.id] = ["", NA]
102102
self.assertEqual(review.get_scores(review.form_data)[0], 0)
103+
104+
105+
class TestReviewScoreDisplay(TestCase):
106+
def test_average_shown_by_default(self):
107+
review = ReviewFactory(score=4.5, total_score=18)
108+
self.assertEqual(review.score_display, "4.5")
109+
110+
@override_settings(REVIEW_SCORE_SHOW_TOTAL=True)
111+
def test_total_shown_when_enabled(self):
112+
review = ReviewFactory(score=4.5, total_score=18)
113+
self.assertEqual(review.score_display, "18")
114+
115+
@override_settings(REVIEW_SCORE_SHOW_TOTAL=True)
116+
def test_review_without_scores_shown_as_dash(self):
117+
review = ReviewFactory(score=NA, total_score=NA)
118+
self.assertEqual(review.score_display, "-")

‎hypha/apply/review/views.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def get_context_data(self, **kwargs):
495495
{"opinions": review.opinions.select_related("author").all()}
496496
)
497497
review_data["opinions"]["answers"].append(opinions_html)
498-
review_data["score"]["answers"].append(review.get_score_display)
498+
review_data["score"]["answers"].append(review.score_display)
499499
review_data["recommendation"]["answers"].append(
500500
review.get_recommendation_display()
501501
)

‎hypha/settings/base.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
REVIEW_VISIBILITY_DEFAULT = env.str("REVIEW_VISIBILITY_DEFAULT", "private")
218218

219219
# Show the total (sum) of a review's scored answers instead of the average of
220-
# them, in the "Reviews & assignees" block on the submission detail page.
220+
# them, wherever a review score is shown.
221221
REVIEW_SCORE_SHOW_TOTAL = env.bool("REVIEW_SCORE_SHOW_TOTAL", False)
222222

223223
# Require an applicant to view their rendered application before submitting

0 commit comments

Comments
 (0)