Skip to content

Commit

Permalink
Fixed linting on backend code
Browse files Browse the repository at this point in the history
  • Loading branch information
nulzo committed Oct 29, 2023
1 parent b4a5175 commit ee8a825
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
3 changes: 1 addition & 2 deletions backend/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@
# path("api/messages/inactive/"),
# path("api/messages/activate/<str:message_pk>"),
# Course URLS
path("api/courses/", view=routing.APICourseList.as_view(),
name="Course List View"),
path("api/courses/", view=routing.APICourseList.as_view(), name="Course List View"),
# path("api/courses/<str:course_pk>", view=routing.MessageViewSet.as_view()),
# path("api/courses/department/<str:dept>"),
# path("api/courses/active/"),
Expand Down
6 changes: 2 additions & 4 deletions backend/src/api/models/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ def get_successful(self):


class Ticket(models.Model):
professor = models.ForeignKey(
Professor, null=True, on_delete=models.PROTECT)
section = models.ForeignKey(
"api.Section", null=True, on_delete=models.PROTECT)
professor = models.ForeignKey(Professor, null=True, on_delete=models.PROTECT)
section = models.ForeignKey("api.Section", null=True, on_delete=models.PROTECT)
issue = models.ForeignKey(Issues, null=True, on_delete=models.PROTECT)
student = models.ForeignKey(
"api.User", null=True, on_delete=models.PROTECT, related_name="student_ticket"
Expand Down
12 changes: 6 additions & 6 deletions backend/src/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class Meta:


class TicketSerializer(serializers.ModelSerializer):
professor = serializers.PrimaryKeyRelatedField(
queryset=Professor.prof.all())
section = serializers.PrimaryKeyRelatedField(
queryset=Section.generic.all())
professor = serializers.PrimaryKeyRelatedField(queryset=Professor.prof.all())
section = serializers.PrimaryKeyRelatedField(queryset=Section.generic.all())
issue = serializers.PrimaryKeyRelatedField(queryset=Issues.generic.all())
student = serializers.PrimaryKeyRelatedField(
queryset=User.generic.all().filter(is_tutor=False))
queryset=User.generic.all().filter(is_tutor=False)
)
tutor = serializers.PrimaryKeyRelatedField(
queryset=User.generic.all().filter(is_tutor=True))
queryset=User.generic.all().filter(is_tutor=True)
)

class Meta:
model = Ticket
Expand Down
30 changes: 12 additions & 18 deletions backend/src/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ def get(self, request):
sections = sections.filter(professor__in=query)

if first_name := querystring.get("first-name"):
query = Professor.prof.filter(
first_name=first_name.capitalize())
query = Professor.prof.filter(first_name=first_name.capitalize())
sections = sections.filter(professor__in=query)

if modality := querystring.get("modality"):
Expand Down Expand Up @@ -458,8 +457,7 @@ def get(self, request):

if querystring:
if department := querystring.get("department"):
courses = courses.filter(
course_department=self.sanitize(department))
courses = courses.filter(course_department=self.sanitize(department))

if name := querystring.get("name"):
courses = courses.filter(course_name=name)
Expand All @@ -471,8 +469,7 @@ def get(self, request):
courses = courses.filter(course_id=course_id)

if course_id_contains := querystring.get("course-id-contains"):
courses = courses.filter(
course_id__contains=course_id_contains)
courses = courses.filter(course_id__contains=course_id_contains)

if greater_than_code := querystring.get("higher-than"):
courses = courses.filter(course_id__gt=greater_than_code)
Expand Down Expand Up @@ -513,8 +510,7 @@ def get(self, request):

if querystring:
if department := querystring.get("department"):
users = users.filter(
course_department=self.sanitize(department))
users = users.filter(course_department=self.sanitize(department))

if name := querystring.get("name"):
users = users.filter(name=name)
Expand Down Expand Up @@ -578,8 +574,7 @@ def get(self, request):

if querystring:
if department := querystring.get("department"):
users = users.filter(
course_department=self.sanitize(department))
users = users.filter(course_department=self.sanitize(department))

if name := querystring.get("name"):
users = users.filter(name=name)
Expand Down Expand Up @@ -664,6 +659,7 @@ def put(self, request, pk=None):

# ------------------------- PROFESSOR ---------------------------


class APITicketView(APIView):
serializer_class = TicketSerializer
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, HTMLFormRenderer)
Expand Down Expand Up @@ -691,8 +687,7 @@ def get(self, request):
querystring = self.get_querystring(request=request)
if querystring:
if is_completed := querystring.get("completed"):
tickets = tickets.filter(
completed=is_completed.upper())
tickets = tickets.filter(completed=is_completed.upper())

serializer = TicketSerializer(tickets, many=True)
return Response(serializer.data)
Expand All @@ -701,16 +696,16 @@ def post(self, request, search=None):
Ticket.generic.all()
if professor_name := request.data.get("professor"):
pid = self.get_professor_id(professor_name=professor_name)
request.data['professor'] = pid.professor_id
request.data["professor"] = pid.professor_id
if course_name := request.data.get("section"):
cid = self.get_course_id(course_name=course_name)
request.data['section'] = cid.id
request.data["section"] = cid.id
if issue_type := request.data.get("issue"):
iid = self.get_issue_id(issue_type=issue_type)
request.data['issue'] = iid.issue_id
request.data["issue"] = iid.issue_id
if student_name := request.data.get("student"):
sid = self.get_user_id(user=student_name)
request.data['student'] = sid.student_nuid
request.data["student"] = sid.student_nuid
print(request.data)
serializer = TicketSerializer(data=request.data)
if serializer.is_valid():
Expand All @@ -737,8 +732,7 @@ def get(self, request):
query_string = self.get_querystring(request=request)
if query_string:
if professor_name := query_string.get("professor"):
professors = professors.filter(
full_name=self.sanitize(professor_name))
professors = professors.filter(full_name=self.sanitize(professor_name))
if professor_id := query_string.get("id"):
professors = professors.filter(professor_id=professor_id)
if professor_first_name := query_string.get("first-name"):
Expand Down

0 comments on commit ee8a825

Please sign in to comment.