Skip to content

Commit

Permalink
New
Browse files Browse the repository at this point in the history
  • Loading branch information
shiva-menta committed Apr 26, 2024
1 parent e678b75 commit 8ee931b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions backend/courses/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import connection
from django.db.models import Q
from django.db.models.aggregates import Count
from django.db.models.expressions import Subquery, Value
from django.db.models.functions.comparison import Coalesce
Expand Down Expand Up @@ -723,9 +724,9 @@ def get_section_from_course_instructor_semester(course_code, professors, semeste
course__semester=semester
)

professors_query = Q(instructors__username=professors[0])
professors_query = Q(instructors__name=professors[0])
for professor in professors[1:]:
professors_query &= Q(instructors__username=professor)
professors_query &= Q(instructors__name=professor)
matching_sections = sections.filter(professors_query).distinct()

if matching_sections.count() == 1:
Expand Down
7 changes: 4 additions & 3 deletions backend/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ def get_queryset(self):
course = get_course_from_code_semester(course_code, semester)
except Http404:
return Response(
{"message": "Course not found."}, status=status.HTTP_404_BAD_REQUEST
{"message": "Course not found."}, status=status.HTTP_404_NOT_FOUND
)
topic = course.topic
return Comment.objects.filter(section__course__topic=topic)
Expand Down Expand Up @@ -995,7 +995,7 @@ def create(self, request):
if Comment.objects.filter(id=request.data.get("id")).exists():
return self.update(request, request.data.get("id"))

if not all(["text", "course_code", "instructor", "semester"], lambda x: x in request.data):
if not all(map(lambda x: x in request.data, ["text", "course_code", "instructor", "semester"])):
return Response(
{"message": "Insufficient fields provided."}, status=status.HTTP_400_BAD_REQUEST
)
Expand All @@ -1008,8 +1008,9 @@ def create(self, request):
request.data.get("semester")
)
except Exception as e:
print(e)
return Response(
{"message": "Section not found."}, status=status.HTTP_404_BAD_REQUEST
{"message": "Section not found."}, status=status.HTTP_404_NOT_FOUND
)

# create comment and send response
Expand Down
10 changes: 5 additions & 5 deletions backend/tests/courses/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,12 +1342,12 @@ def setUp(self):
self.section.instructors.add(Instructor.objects.get_or_create(name="default prof")[0])

# Create Base Level Comments
self.id1 = self.create_comment("user1", "default prof", self._COURSE_CODE, TEST_SEMESTER, None)
self.id2 = self.create_comment("user2", "default prof", self._COURSE_CODE, "2012A", None)
self.id1 = self.create_comment("user1", ["default prof"], self._COURSE_CODE, TEST_SEMESTER, None)
self.id2 = self.create_comment("user2", ["default prof"], self._COURSE_CODE, "2012A", None)

# Reply to Comment
self.id3 = self.create_comment("user3", "default prof", self._COURSE_CODE, TEST_SEMESTER, self.id1)
self.id4 = self.create_comment("user1", "default prof", self._COURSE_CODE, TEST_SEMESTER, self.id1)
self.id3 = self.create_comment("user3", ["default prof"], self._COURSE_CODE, TEST_SEMESTER, self.id1)
self.id4 = self.create_comment("user1", ["default prof"], self._COURSE_CODE, TEST_SEMESTER, self.id1)

# Add Vote Counts
self.upvote("user1", self.id2)
Expand Down Expand Up @@ -1377,7 +1377,7 @@ def create_comment(self, username, instructor, code, semester, parent_id):
if parent_id != None:
data["parent_id"] = parent_id

response = self.client.post(reverse("comment"), data)
response = self.client.post(reverse("comment"), data, format="json")
self.client.logout()
print(response.data)
return response.data["id"]
Expand Down

0 comments on commit 8ee931b

Please sign in to comment.