示例#1
0
def newQuiz(request):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    serializer = CreateNewQuiz(data=request.data)
    if serializer.is_valid():
        new_serializer = serializer.save(subject=teacher.subject.name,
                                         author=user)

        return Response(new_serializer.data)
示例#2
0
def listUnLaunchedQuiz(request):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    quizs = Quiz.objects.filter(quiz_author=teacher, quiz_is_launched=False)
    serializer = CreateNewQuiz(quizs, many=True)

    return Response({'quizs': serializer.data})
示例#3
0
def listAllStudentQuizs(request):
    user = request.user
    student = get_object_or_404(Student, user=user)
    class_room = student.class_room
    past_quizs = Quiz.objects.filter(quiz_is_launched=True,
                                     quiz_launch_time__lt=timezone.now(),
                                     quiz_class_room=class_room)
    past_quizs_serializer = CreateNewQuiz(past_quizs, many=True)
    future_quizs = Quiz.objects.filter(quiz_is_launched=True,
                                       quiz_launch_time__gt=timezone.now(),
                                       quiz_class_room=class_room)
    future_quizs_serializer = CreateNewQuiz(future_quizs, many=True)

    return Response({
        'past': past_quizs_serializer.data,
        'future': future_quizs_serializer.data,
    })
示例#4
0
def newQuiz(request):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    serializer = CreateNewQuiz(data=request.data)
    questions = request.data.get('questions')
    usedQuestions = questions.split('&')
    if serializer.is_valid():
        quiz_id = int(random.random() * 1000)
        new_serializer = serializer.save(subject=teacher.subject.name,
                                         author=user,
                                         quiz_id=quiz_id)
        for q in usedQuestions:
            theSpecificQuestion = get_object_or_404(Question, id=int(q))
            new_serializer.quiz_questions.add(theSpecificQuestion)
        return Response({
            'id': new_serializer.id,
        }, 200)
    else:
        return Response({'error': serializer.errors}, 403)
示例#5
0
def saveQuiz(request, quiz_id):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    quiz = get_object_or_404(Quiz, quiz_id=int(quiz_id))
    if quiz.quiz_author != teacher:
        return Response({'user': '******'})
    qustions = quiz.quiz_questions.all()
    QTime = 0
    for e in qustions:
        QTime += e.question_customization_time
    quiz.set_quiz_real_time(QTime)
    quiz.set_quiz_setion_time(QTime + 300)
    quiz.save()

    return Response(CreateNewQuiz(quiz).data)
示例#6
0
def launchQuiz(request, quiz_id, quiz_launch_time, quiz_class_room):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    quiz = get_object_or_404(Quiz, quiz_id=int(quiz_id))
    if quiz.quiz_author != teacher:
        return Response({'user': '******'})
    quiz.set_quiz_is_launched(True)
    quiz.set_quiz_launch_time(quiz_launch_time)
    class_rooms = quiz_class_room.split('&')
    for room in class_rooms:
        class_room = get_object_or_404(ClassRoom, id=int(room))
        if (not class_room):
            return Response({'class_room': 'class room not exist'})
        quiz.quiz_class_room.add(class_room)
    quiz.save()

    return Response(CreateNewQuiz(quiz).data)
示例#7
0
def detailQuiz(request, quiz_id):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    quiz = get_object_or_404(Quiz, id=int(quiz_id))
    serializer = CreateNewQuiz(quiz)
    questions = quiz.quiz_questions.all()
    questions_serializer = CreateQuestion(questions, many=True)
    Qlist = [e for e in questions]
    mcq = MCQ.objects.filter(question__in=Qlist)
    mcq_serializer = CreateMCQ(mcq, many=True)
    tr = TR.objects.filter(question__in=Qlist)
    tr_serializer = CreateTR(tr, many=True)

    return Response({
        'quiz': serializer.data,
        'Q': questions_serializer.data,
        'mcq': mcq_serializer.data,
        'tr': tr_serializer.data
    })