Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1d5c6bf
autocomplete backend, js frontend, some html (needs work)
pelin-sayar Nov 2, 2025
d3c8869
feat(autocomplete): dry view and cursor hover for results
artiehumphreys Nov 10, 2025
eb56903
searchbar html and css fixes
brandonistfan Dec 7, 2025
f3e3470
lint fixes
brandonistfan Dec 7, 2025
c05c6ed
fix(styling): url import
artiehumphreys Dec 26, 2025
a5167c4
feat(autocomplete): autocomplete for clubs
artiehumphreys Dec 26, 2025
a08e602
fix(lint)
artiehumphreys Dec 26, 2025
e65d41f
fix(autocomplete): club results now show
artiehumphreys Dec 26, 2025
6beb4c7
autocomplete backend, js frontend, some html (needs work)
pelin-sayar Nov 2, 2025
95d802d
feat(autocomplete): dry view and cursor hover for results
artiehumphreys Nov 10, 2025
d303312
searchbar html and css fixes
brandonistfan Dec 7, 2025
8676527
lint fixes
brandonistfan Dec 7, 2025
b01d419
fix(styling): url import
artiehumphreys Dec 26, 2025
61ab588
feat(autocomplete): autocomplete for clubs
artiehumphreys Dec 26, 2025
e0033d4
fix(lint)
artiehumphreys Dec 26, 2025
c56b6c6
fix(autocomplete): club results now show
artiehumphreys Dec 26, 2025
99bd7e8
Merge branch 'autocomplete' of https://github.com/thecourseforum/theC…
artiehumphreys Mar 29, 2026
3db5b7f
autocomplete backend, js frontend, some html (needs work)
pelin-sayar Nov 2, 2025
acc20ec
feat(autocomplete): dry view and cursor hover for results
artiehumphreys Nov 10, 2025
8cfee85
searchbar html and css fixes
brandonistfan Dec 7, 2025
8bd2186
lint fixes
brandonistfan Dec 7, 2025
ce12097
fix(styling): url import
artiehumphreys Dec 26, 2025
eb5cde6
feat(autocomplete): autocomplete for clubs
artiehumphreys Dec 26, 2025
b7fa2cb
fix(lint)
artiehumphreys Dec 26, 2025
66364e6
fix(autocomplete): club results now show
artiehumphreys Dec 26, 2025
d0709ba
feat(autocomplete): parallelizing course + instructor fetching
artiehumphreys Mar 29, 2026
6d657e2
made results display dynamically depending on screen size, wrote test…
pelin-sayar Mar 29, 2026
e8b7f76
resolved merge conflicts
pelin-sayar Mar 29, 2026
8e4780f
forgot MAX_RESULTS as a const so fixed that
pelin-sayar Mar 29, 2026
1482bae
missed a conflict earlier should be good now
pelin-sayar Mar 29, 2026
4445505
2 tests are failing, will look into more throughout the week
pelin-sayar Mar 29, 2026
f2744bd
autocomplete tests now work yayy
pelin-sayar Apr 5, 2026
b793d41
added docstring to test file
pelin-sayar Apr 5, 2026
cd1ad9a
added more docstrings to methods
pelin-sayar Apr 5, 2026
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
215 changes: 215 additions & 0 deletions tcf_website/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
"""DRF Serializers"""

from rest_framework import serializers

from ..models import (
Club,
ClubCategory,
Course,
Department,
Instructor,
School,
Semester,
Subdepartment,
)


class SemesterSerializer(serializers.ModelSerializer):
"""DRF Serializer for Semester"""

season = serializers.SerializerMethodField()

def get_season(self, obj):
"""Change the `season` field to TitleCase (or PascalCase)"""
return obj.season.title()

class Meta:
model = Semester
fields = "__all__"


class SchoolSerializer(serializers.ModelSerializer):
"""DRF Serializer for School"""

class Meta:
model = School
fields = "__all__"


class DepartmentSerializer(serializers.ModelSerializer):
"""DRF Serializer for Department"""

school = SchoolSerializer(read_only=True)

class Meta:
model = Department
fields = "__all__"


class SubdepartmentSerializer(serializers.ModelSerializer):
"""DRF Serializer for Subdepartment"""

class Meta:
model = Subdepartment
fields = "__all__"


class CourseSerializer(serializers.ModelSerializer):
"""DRF Serializer for Course"""

subdepartment = SubdepartmentSerializer(read_only=True)

class Meta:
model = Course
fields = "__all__"


class CourseSimpleStatsSerializer(CourseSerializer):
"""DRF Serializer for Course including some review statistics"""

semester_last_taught = SemesterSerializer(read_only=True)
average_rating = serializers.FloatField(allow_null=True)
average_difficulty = serializers.FloatField(allow_null=True)
average_gpa = serializers.FloatField(allow_null=True)

class Meta:
model = Course
fields = [
"id",
"title",
"description",
"number",
"subdepartment",
"semester_last_taught",
"average_rating",
"average_difficulty",
"average_gpa",
"is_recent",
]


class CourseAllStatsSerializer(CourseSimpleStatsSerializer):
"""DRF Serializer for Course including all review statistics"""

# ratings
average_instructor = serializers.FloatField(allow_null=True)
average_fun = serializers.FloatField(allow_null=True)
average_recommendability = serializers.FloatField(allow_null=True)
# workload
average_hours_per_week = serializers.FloatField(allow_null=True)
average_amount_reading = serializers.FloatField(allow_null=True)
average_amount_writing = serializers.FloatField(allow_null=True)
average_amount_group = serializers.FloatField(allow_null=True)
average_amount_homework = serializers.FloatField(allow_null=True)
# grades
a_plus = serializers.IntegerField(allow_null=True)
a = serializers.IntegerField(allow_null=True)
a_minus = serializers.IntegerField(allow_null=True)
b_plus = serializers.IntegerField(allow_null=True)
b = serializers.IntegerField(allow_null=True)
b_minus = serializers.IntegerField(allow_null=True)
c_plus = serializers.IntegerField(allow_null=True)
c = serializers.IntegerField(allow_null=True)
c_minus = serializers.IntegerField(allow_null=True)
dfw = serializers.IntegerField(allow_null=True)
total_enrolled = serializers.IntegerField(allow_null=True)

class Meta:
model = Course
fields = [
"id",
"title",
"description",
"number",
"subdepartment",
"semester_last_taught",
"is_recent",
# ratings
"average_rating",
"average_instructor",
"average_fun",
"average_recommendability",
"average_difficulty",
# workload
"average_hours_per_week",
"average_amount_reading",
"average_amount_writing",
"average_amount_group",
"average_amount_homework",
# grades
"a_plus",
"a",
"a_minus",
"b_plus",
"b",
"b_minus",
"c_plus",
"c",
"c_minus",
"dfw",
"total_enrolled",
"average_gpa",
]


class CourseAutocompleteSerializer(serializers.ModelSerializer):
"""DRF Serializer for autocomplete course"""

subdepartment = serializers.CharField(
source="subdepartment.mnemonic", read_only=True
)

class Meta:
model = Course
fields = ["id", "title", "number", "subdepartment"]


class InstructorSerializer(serializers.ModelSerializer):
"""DRF Serializer for Instructor"""

class Meta:
model = Instructor
fields = "__all__"


class InstructorAutocompleteSerializer(serializers.ModelSerializer):
"""DRF Serializer for autocomplete instructor"""

class Meta:
model = Instructor
fields = [
"id",
"full_name",
]


class ClubCategorySerializer(serializers.ModelSerializer):
"""DRF Serializer for ClubCategory"""

class Meta:
model = ClubCategory
fields = "__all__"


class ClubSerializer(serializers.ModelSerializer):
"""DRF Serializer for Club"""

category = ClubCategorySerializer(read_only=True)

class Meta:
model = Club
fields = "__all__"


class ClubAutocompleteSerializer(serializers.ModelSerializer):
"""DEF Serializer for Club autocomplete"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typo in docstring.

The docstring has "DEF Serializer" but should be "DRF Serializer" (Django REST Framework).

🔎 Proposed fix
-    """DEF Serializer for Club autocomplete"""
+    """DRF Serializer for Club autocomplete"""
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""DEF Serializer for Club autocomplete"""
"""DRF Serializer for Club autocomplete"""
🤖 Prompt for AI Agents
In tcf_website/api/serializers.py around line 205, the docstring contains a typo
"DEF Serializer for Club autocomplete"; update the docstring to read "DRF
Serializer for Club autocomplete" to correctly reference Django REST Framework
and save the file.


category_name = serializers.CharField(source="category.name", read_only=True)

class Meta:
model = Club
fields = (
"id",
"name",
"category_name",
)
Loading
Loading