Skip to content

Commit 158dc0a

Browse files
authored
Merge pull request #1010 from thecourseforum/filter-empty-reviews
Fix number of reviews for course instructor
2 parents c34e23a + 9795a5a commit 158dc0a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tcf_website/templates/course/course_professor.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2 class="mr-md-3">{{ course.title }}</h2>
6666
<div class="ratings-row">
6767
<div class="rating-card">
6868
<span class="rating-card-num rating-num">&mdash;</span>
69-
<p class="rating-card-desc"><i class="fa fa-star fa-fw"></i>&nbsp;{{ num_reviews }} {% if num_reviews == 1 %} Rating {% else %} Ratings {% endif %}</p>
69+
<p class="rating-card-desc"><i class="fa fa-star fa-fw"></i>&nbsp;{{ num_ratings }} {% if num_ratings == 1 %} Rating {% else %} Ratings {% endif %}</p>
7070
</div>
7171
<div class="info-container">
7272
<div class="info-row">
@@ -243,7 +243,7 @@ <h2 class="mr-md-3">{{ course.title }}</h2>
243243
<div class="tab-pane fade show active" id="reviewsTabContent" role="tabpanel" aria-labelledby="reviews-tab">
244244
<div class="reviews-container mb-5 mt-3">
245245
<div class="reviews-toolbar pb-2 d-flex flex-md-row flex-column justify-content-left justify-content-md-center">
246-
<h3 class="reviews-heading mb-0 mt-1 mr-4">{{ num_reviews }} {% if num_reviews == 1 %} Comment {% else %} Comments {% endif %}</h3>
246+
<h3 class="reviews-heading mb-0 mt-1 mr-4">{{ num_reviews }} {% if num_reviews == 1 %} Review {% else %} Reviews {% endif %}</h3>
247247
<div class="reviews-options d-flex flex-sm-row flex-column col p-0">
248248
{% if user.is_authenticated %}
249249
<a href="{% url 'new_review' %}?subdept_id={{course.subdepartment.id}}&course_id={{course.id}}&instr_id={{instructor.id}}" class="btn bg-tcf-orange text-white mb-3">

tcf_website/views/browse.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Any
77

88
from django.core.exceptions import ObjectDoesNotExist
9-
from django.db.models import Avg, CharField, F, Q, Value
9+
from django.db.models import Avg, CharField, Count, F, Q, Value
1010
from django.db.models.functions import Concat
1111
from django.http import Http404
1212
from django.shortcuts import get_object_or_404, redirect, render
@@ -194,8 +194,11 @@ def course_instructor(request, course_id, instructor_id, method="Most Recent"):
194194
course = section_last_taught.course
195195
instructor = section_last_taught.instructors.get(pk=instructor_id)
196196

197-
# Find the total number of reviews (with or without text) for the given course
198-
num_reviews = Review.objects.filter(instructor=instructor_id, course=course_id).count()
197+
# ratings: reviews with and without text; reviews: ratings with text
198+
reviews = Review.objects.filter(instructor=instructor_id, course=course_id).aggregate(
199+
num_ratings=Count("id"), num_reviews=Count("id", filter=~Q(text=""))
200+
)
201+
num_reviews, num_ratings = reviews["num_reviews"], reviews["num_ratings"]
199202

200203
dept = course.subdepartment.department
201204

@@ -295,6 +298,7 @@ def course_instructor(request, course_id, instructor_id, method="Most Recent"):
295298
"course_id": course_id,
296299
"instructor": instructor,
297300
"semester_last_taught": section_last_taught.semester,
301+
"num_ratings": num_ratings,
298302
"num_reviews": num_reviews,
299303
"paginated_reviews": paginated_reviews,
300304
"breadcrumbs": breadcrumbs,

0 commit comments

Comments
 (0)