From 0904d3d17254da1f175ca2dba60dbec1595bdf05 Mon Sep 17 00:00:00 2001 From: gmurtaza00 <111306331+gmurtaza00@users.noreply.github.com> Date: Fri, 28 Apr 2023 02:49:06 -0400 Subject: [PATCH] Average total score in review and assignee box (#3341) Added Average total score in the Reviews & assignee's box. Closes #3340 --------- Co-authored-by: Chris Zubak-Skees <chriszs@gmail.com> --- .../funds/includes/review_sidebar.html | 17 ++++++++++------- hypha/apply/review/templatetags/review_tags.py | 17 +++++++++++++++++ .../sass/apply/components/_reviews-sidebar.scss | 6 ------ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/hypha/apply/funds/templates/funds/includes/review_sidebar.html b/hypha/apply/funds/templates/funds/includes/review_sidebar.html index c07359379..e584ba00c 100644 --- a/hypha/apply/funds/templates/funds/includes/review_sidebar.html +++ b/hypha/apply/funds/templates/funds/includes/review_sidebar.html @@ -1,12 +1,15 @@ {% load i18n review_tags %} -<ul class="reviews-sidebar" x-data='{showHiddenReviewers: false}'> - <li class="reviews-sidebar__item reviews-sidebar__item--header"> - <div></div> - <div>{{ recommendation|traffic_light }}</div> - <div></div> - </li> - +<div class="flex items-center justify-around px-2 py-1 bg-gray-100"> + <span> + {{ recommendation|traffic_light }} + </span> + <span class="font-medium"> + {% trans 'Avg. Score'%}: {{assigned_reviewers|average_review_score|floatformat:'1'}} + </span> +</div> + +<ul class="reviews-sidebar mt-4" x-data='{showHiddenReviewers: false}'> {% if not staff_reviewers_exist %} <li class="reviews-sidebar__no-reviews">{% trans "No staff reviewers yet" %}</li> <hr class="reviews-sidebar__split"> diff --git a/hypha/apply/review/templatetags/review_tags.py b/hypha/apply/review/templatetags/review_tags.py index b240d5ede..7c0aac1b6 100644 --- a/hypha/apply/review/templatetags/review_tags.py +++ b/hypha/apply/review/templatetags/review_tags.py @@ -2,6 +2,7 @@ from django import template from django.utils.safestring import mark_safe from ..models import MAYBE, NO, YES +from ..options import NA register = template.Library() @@ -40,3 +41,19 @@ def can_review(user, submission): @register.filter def has_draft(user, submission): return submission.can_review(user) and submission.assigned.draft_reviewed().filter(reviewer=user).exists() + + +@register.filter +def average_review_score(reviewers): + if reviewers: + scores = [ + reviewer.review.score + for reviewer in reviewers + if not reviewer.has_review and not reviewer.review.is_draft and not reviewer.review.score == NA + ] + if len(scores) > 0: + return sum(scores) / len(scores) + else: + return 0 + else: + return reviewers diff --git a/hypha/static_src/src/sass/apply/components/_reviews-sidebar.scss b/hypha/static_src/src/sass/apply/components/_reviews-sidebar.scss index 44a5bb753..d34b31ed6 100644 --- a/hypha/static_src/src/sass/apply/components/_reviews-sidebar.scss +++ b/hypha/static_src/src/sass/apply/components/_reviews-sidebar.scss @@ -51,12 +51,6 @@ } } - &--header { - background-color: $color--light-grey; - padding: 10px; - align-items: center; - } - &.is-hidden { display: none; } -- GitLab