Skip to content

Commit

Permalink
Merge pull request #1057 from jchen324/feature/evaluations
Browse files Browse the repository at this point in the history
Evaluations: Add endpoint and update display of evaluations
  • Loading branch information
JiaqiWang18 authored Dec 9, 2023
2 parents 0cd718f + d84037f commit 05ebbe6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions courses/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

urlpatterns = [
re_path(r"^courses/?$", courses.views.all_courses),
re_path(r"^courses/json/?$", courses.views.all_courses_json),
re_path(r"c/(?P<code>.+?)/?$", courses.views.course_page),
re_path(
r"course/(?P<code>.+?)/(?P<sem_name>.+?)/(?P<year>.+?)/?$",
Expand Down
22 changes: 21 additions & 1 deletion courses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import json
from datetime import datetime

from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render, get_object_or_404
from django.template import RequestContext
from pytz import timezone
Expand Down Expand Up @@ -61,6 +61,26 @@ def all_courses(request):
return render(request, "all_courses.html", context)


def all_courses_json(request):
"""
Returns all course names and codes in JSON.
"""
school = request.subdomain
courses = Course.objects.filter(school=school).all()

# Create a list of dictionaries with course name and code
courses_data = [
{
"name": course.name,
"code": course.code,
}
for course in courses
]

# Return as JSON
return JsonResponse(courses_data, safe=False)


def get_classmates_in_course(request, school, sem_name, year, course_id):
"""
Finds all classmates for the authenticated user who also have a
Expand Down
2 changes: 1 addition & 1 deletion static/js/redux/ui/evaluation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Evaluation extends React.Component {
<div className="year truncate">
<b>
{year}
{!evalData.unique_term_year && shortProfName(evalData.professor)}
{shortProfName(evalData.professor)}
</b>
</div>
{prof}
Expand Down
10 changes: 9 additions & 1 deletion static/js/redux/ui/evaluation_list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ class EvaluationList extends React.Component {

const evals = evalInfo
.sort((e1, e2) => EvaluationList.evalCompare(e1, e2))
.map((e) => <Evaluation evalData={e} key={e.id} />);
.map((e) => {
if (e.summary && e.summary.trim() !== "") {
// Render the Evaluation component if the summary is not an empty string
return <Evaluation evalData={e} key={e.id} />;
} else {
// Render an empty div if the summary is an empty string
return <div key={e.id} style={{ display: "none" }} />;
}
});

// console.log(navs, evals);

Expand Down

0 comments on commit 05ebbe6

Please sign in to comment.