# Path: students/permissions.py
# class IsTeacher(permissions.BasePermission):
#     message = ROLE_DEFAULT_MESSAGE.format('teacher')
# 
#     def has_permission(self, request, view):
#         return Teacher.objects.filter(user=request.user).exists()
# 
# class IsStudent(permissions.BasePermission):
#     message = ROLE_DEFAULT_MESSAGE.format('student')
# 
#     def has_permission(self, request, view):
#         return Student.objects.filter(user=request.user).exists()


from rest_framework import filters
from students.permissions import IsTeacher, IsStudent



class HomeworksFilterBackend(filters.BaseFilterBackend):
    def filter_queryset(self, request, queryset, view):
        if IsTeacher().has_permission(request, self):
            return queryset.filter(subject=request.user.teacher.subject)

        return queryset.filter(clazz=request.user.student.clazz)


class SubmissionsFilterBackend(filters.BaseFilterBackend):
    def filter_queryset(self, request, queryset, view):

# Path: students/permissions.py
# class IsTeacher(permissions.BasePermission):
#     message = ROLE_DEFAULT_MESSAGE.format('teacher')
# 
#     def has_permission(self, request, view):
#         return Teacher.objects.filter(user=request.user).exists()
# 
# class IsStudent(permissions.BasePermission):
#     message = ROLE_DEFAULT_MESSAGE.format('student')
# 
#     def has_permission(self, request, view):
#         return Student.objects.filter(user=request.user).exists()


# Path: homeworks/filters.py
from rest_framework import filters
from students.permissions import IsTeacher, IsStudent




class HomeworksFilterBackend(filters.BaseFilterBackend):
    def filter_queryset(self, request, queryset, view):
        if IsTeacher().has_permission(request, self):
            return queryset.filter(subject=request.user.teacher.subject)

        return queryset.filter(clazz=request.user.student.clazz)


class SubmissionsFilterBackend(filters.BaseFilterBackend):
    def filter_queryset(self, request, queryset, view):

        if IsStudent().has_permission(request, self):