Exemplo n.º 1
0
def createQuestion(request):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    question = CreateQuestion(data=request.data)
    mcq = CreateMCQ(data=request.data)
    if question.is_valid() and mcq.is_valid():
        q_serializer = question.save(author=user, subject=teacher.subject.name)
        mcq_serializer = mcq.save(question=q_serializer)
        return Response({'Q': question.data, 'MCQ': mcq.data})
    return Response({'Q': question.errors, 'MCQ': mcq.errors})
Exemplo n.º 2
0
def viewRates(request, question_id):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    question = get_object_or_404(Question,
                                 id=question_id,
                                 question_author=teacher)
    q_serializer = CreateQuestion(question)
    t_serializer = None
    x_name = ''
    if question.question_type == 'MCQ':
        mcq = get_object_or_404(MCQ, question=question)
        t_serializer = CreateMCQ(mcq)
        x_name = 'MCQ'
    else:
        tr = get_object_or_404(TR, question=question)
        t_serializer = CreateTR(tr)
        x_name = 'TR'
    rates = Rate.objects.filter(question=question)
    serializer = CreateRate(rates, many=True)
    return Response(
        {
            'reviews': serializer.data,
            'Q': q_serializer.data,
            '{}'.format(x_name): t_serializer.data
        }, 200)
Exemplo n.º 3
0
def listQuestions(request):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    questions = Question.objects.filter(question_subject=teacher.subject)
    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({
        'Q': questions_serializer.data,
        'MCQ': mcq_serializer.data,
        'TR': tr_serializer.data
    })
Exemplo n.º 4
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
    })
Exemplo n.º 5
0
def listTeacherQuestions(request):
    user = request.user
    teacher = get_object_or_404(Teacher, user=user)
    questions = Question.objects.filter(question_subject=teacher.subject,
                                        question_author=teacher)
    if (questions.count() < 1):
        return Response({'data': 'user has no questions'}, 403)
    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({
        'Q': questions_serializer.data,
        'MCQ': mcq_serializer.data,
        'TR': tr_serializer.data
    })