Ejemplo n.º 1
0
    def get(self, request, format=None):

        messages = get_user_messages(request.user.id)

        if messages is not None:
            serializer = serialize(serializers.IMSerializer, messages)

            return Response(serializer.data)

        return Response(status=status.HTTP_204_NO_CONTENT)
Ejemplo n.º 2
0
    def get(self, request, username, format=None):

        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)

        serializer = serialize(serializers.UserSerializer, user)

        return Response(serializer.data)
Ejemplo n.º 3
0
    def get(self, request, task_id, format=None):

        try:
            task = Task.objects.get(pk=task_id)
        except Task.DoesNotExist:
            return Response(status=status.HTTP_204_NO_CONTENT)

        task.solved = Solution.is_task_solved(task_id, request.user)

        serializer = serialize(serializers.TaskOnlySerializer, task)

        return Response(serializer.data)
Ejemplo n.º 4
0
def generate_tests(path_to_script, user_id):

    is_ok, result = _generate_tests(path_to_script)

    if not is_ok:
        Task.remove_test_generator(path_to_script)

        im.send_message(user_id=user_id,
                        msg_type='error_testgenerating',
                        message=result,
                        alert_msg='Во время генерации тестов произошла ошибка')
    else:
        serializer = serializers.serialize(
            serializers.TestGenResultsSerializer, result)

        im.send_message(user_id=user_id,
                        msg_type='ok_testgenerating',
                        message=serializer.data,
                        alert_msg='Генерация тестов завершена успешно')
Ejemplo n.º 5
0
    def get(self, request, format=None):

        data = deserialize(serializers.UserInParamsSerializer,
                           request.query_params).data

        if 'user' in data:
            try:
                user = User.objects.get(username=data['user'])
            except User.DoesNotExist:
                return Response(status=status.HTTP_404_NOT_FOUND)
        else:
            user = request.user

        tasks = Task.all_with_user_solution(user)
        serializer = serialize(serializers.TasksListSerializer,
                               tasks,
                               many=True)

        return Response(serializer.data)
Ejemplo n.º 6
0
    def get(self, request, format=None):

        data = deserialize(serializers.SolutionsListParamsSerializer,
                           request.query_params).data

        if request.user.username != data['username']:
            if not request.user.is_staff:
                return Response(status=status.HTTP_403_FORBIDDEN)

            try:
                user = User.objects.get(username=data['username'])
            except User.DoesNotExist:
                return Response(status=status.HTTP_404_NOT_FOUND)
        else:
            user = request.user

        solutions = Solution.get_by_task_user(data['task_id'], user)

        serializer = serialize(serializers.SolutionsListSerializer,
                               solutions,
                               many=True)

        return Response(serializer.data)
Ejemplo n.º 7
0
    def get(self, request, format=None):

        if request.user.is_staff:
            users = User.objects.filter(is_staff=False)
            for user in users:
                user_tasks = Task.all_with_user_solution(user)
                tasks_solved = len([_ for _ in user_tasks if _.solved == 1])
                tasks_failed = len([_ for _ in user_tasks if _.solved == 0])
                tasks_untouched = len(
                    [_ for _ in user_tasks if _.solved == -1])
                #
                setattr(user, 'tasks_solved', tasks_solved)
                setattr(user, 'tasks_failed', tasks_failed)
                setattr(user, 'tasks_untouched', tasks_untouched)

            serializer = serialize(serializers.UserSerializer,
                                   users,
                                   many=True)
            users_data = serializer.data

            return Response(users_data)
        else:
            return Response(status=status.HTTP_403_FORBIDDEN)
Ejemplo n.º 8
0
    def get(self, request, format=None):

        data = deserialize(serializers.CommentsListParamsSerializer,
                           request.query_params).data

        if request.user.username != data['username']:
            if not request.user.is_staff:
                return Response(status=status.HTTP_403_FORBIDDEN)

            try:
                user = User.objects.get(username=data['username'])
            except User.DoesNotExist:
                return Response(status=status.HTTP_404_NOT_FOUND)
        else:
            user = request.user

        comments = Comment.objects.filter(task__id=data['task_id'],
                                          task_owner=user).order_by('-id')

        serializer = serialize(serializers.CommentSerializer,
                               comments,
                               many=True)

        return Response(serializer.data)