コード例 #1
0
    def is_teacher_or_superuser(class_id, request):
        the_class = get_object(ClassRoom, pk=class_id)

        if request.user.is_superuser:
            return True

        return the_class.teacher == request.user.user_profile
コード例 #2
0
    def has_permission(self, request, view):
        quiz_answer = get_object(QuizAnswer,
                                 pk=view.kwargs.get('quiz_answer_id'))
        user_profile = request.user.user_profile

        class_id = quiz_answer.quiz.class_room.id

        if IsTeacherOrSuperuser.is_teacher_or_superuser(class_id, request):
            return True

        return quiz_answer.user_profile == user_profile
コード例 #3
0
    def has_permission(self, request, view):

        if request.method in SAFE_METHODS:
            return True

        from core.views import AddQuizQuestion, QuizUpdateView
        from core.views import RUDQuestion

        if type(view) in [AddQuizQuestion, QuizUpdateView]:
            quiz = get_object(Quiz, pk=view.kwargs.get('quiz_id'))
            class_id = quiz.class_room.id

        elif type(view) == RUDQuestion:
            question = get_object(Question, pk=view.kwargs.get('question_id'))
            quiz = question.quiz
            class_id = quiz.class_room.id
        else:
            class_id = view.kwargs.get('class_id')

        return self.is_teacher_or_superuser(class_id, request)
コード例 #4
0
    def has_permission(self, request, view):
        quiz = get_object(Quiz, pk=view.kwargs.get('quiz_id'))

        if IsTeacherOrSuperuser.is_teacher_or_superuser(
                quiz.class_room.id, request):
            return True

        if not IsEnrolledInClass.is_enrolled_in_class(quiz.class_room.id,
                                                      request):
            return False

        return timezone.now() > quiz.start_datetime
コード例 #5
0
    def delete(request, *args, **kwargs):
        try:
            user_profile = UserProfile.objects.get(
                user__username=kwargs.get('user_username'))
        except UserProfile.DoesNotExist:
            return Response({'username': [
                "User name does not exist",
            ]},
                            status=404)
        class_room = get_object(ClassRoom, pk=kwargs.get('class_id'))
        class_room.students.remove(user_profile)

        return Response({}, status=204)
コード例 #6
0
    def post(request, *args, **kwargs):
        try:
            user_profile = UserProfile.objects.get(
                user__username=kwargs.get('user_username'))
        except UserProfile.DoesNotExist:
            return Response({'username': [
                "User name does not exist",
            ]},
                            status=404)

        class_room = get_object(ClassRoom, pk=kwargs.get('class_id'))

        class_room.students.add(user_profile)
        return Response(UserProfileSerializer(instance=user_profile).data,
                        status=200)
コード例 #7
0
    def has_permission(self, request, view):

        from core.views import QuizQuestionsList, StartQuiz, ClassRoomRetrieveView

        if type(view) in [QuizQuestionsList, StartQuiz]:
            quiz = get_object(Quiz, pk=view.kwargs.get('quiz_id'))
            class_id = quiz.class_room.id
        elif type(view) in [
                ClassRoomRetrieveView,
        ]:
            class_id = view.kwargs.get('class_id')
        else:
            raise APIException("Invalid Permission Usage")

        return self.is_enrolled_in_class(class_id, request)
コード例 #8
0
 def perform_create(self, serializer):
     _class = get_object(ClassRoom, pk=self.kwargs.get('class_id'))
     serializer.save(class_room=_class)
コード例 #9
0
    def delete(request, *args, **kwargs):
        user_profile = request.user.user_profile
        _class = get_object(ClassRoom, pk=kwargs.get('class_id'))
        _class.students.remove(user_profile)

        return Response({}, status=204)
コード例 #10
0
 def perform_create(self, serializer):
     quiz = get_object(Quiz, pk=self.kwargs.get('quiz_id'))
     serializer.save(quiz=quiz)
コード例 #11
0
 def get_queryset(self):
     quiz = get_object(Quiz, pk=self.kwargs.get('quiz_id'))
     return quiz.questions.all()
コード例 #12
0
 def get_queryset(self):
     the_quiz = get_object(Quiz, pk=self.kwargs.get('quiz_id'))
     return the_quiz.answers.all()
コード例 #13
0
 def has_permission(self, request, view):
     quiz = get_object(Quiz, pk=view.kwargs.get('quiz_id'))
     return quiz.is_active
コード例 #14
0
    def is_enrolled_in_class(class_id, request):
        the_class = get_object(ClassRoom, pk=class_id)

        return request.user.user_profile in the_class.students.all()