Example #1
0
 def add_single_choice_question(self, request, pk=None):
     """
     Add a single choice correct Question
     """
     question_module = get_object_or_404(QuestionModule, pk=pk)
     self.check_object_permissions(request, question_module)
     serializer = serializers.SingleChoiceQuestionSerializer(
         data=request.DATA)
     if serializer.is_valid():
         serializer.data['question_module'] = question_module
         serializer.data['quiz'] = question_module.quiz
         question = SingleChoiceQuestion(**serializer.data)
         question.save()
         serializer = serializers.SingleChoiceQuestionSerializer(question)
         return Response(serializer.data)
     else:
         content = serializer.errors
         return Response(content, status.HTTP_400_BAD_REQUEST)
Example #2
0
 def add_single_choice_question(self, request, pk=None):
     """
     Add a single choice correct Question
     """
     question_module = get_object_or_404(QuestionModule, pk=pk)
     self.check_object_permissions(request, question_module)
     serializer = serializers.SingleChoiceQuestionSerializer(
         data=request.DATA)
     if serializer.is_valid():
         serializer.data['question_module'] = question_module
         serializer.data['quiz'] = question_module.quiz
         question = SingleChoiceQuestion(**serializer.data)
         question.save()
         serializer = serializers.SingleChoiceQuestionSerializer(question)
         return Response(serializer.data)
     else:
         content = serializer.errors
         return Response(content, status.HTTP_400_BAD_REQUEST)
Example #3
0
                print(e)


        for question in quiz.findall(question_xpath):
            qtype = question.attrib[tscIQ + 'type']
            qtext = question[0].text
            if qtype == 'MC':
                # print "multiple choice"
                # answer_xpath = ".//" + tscIQ + "correctAnswer"
                answer = int(math.log(int(question[1].text), 2))
                options = json.dumps(
                    [opt.text for opt in
                        question.findall(".//" + tscIQ + "answer")]
                )
                q = SingleChoiceQuestion(
                    quiz=quiz_obj, question_module=qmodule_obj,
                    description=qtext, options=options, answer=answer, marks=1
                )
                q.save()
            elif qtype == 'FITB':
                # print "fixed answer"
                answer = json.dumps(
                    [ans.text for ans in
                        question.findall(".//" + tscIQ + "answer")]
                )
                q = FixedAnswerQuestion(
                    quiz=quiz_obj, question_module=qmodule_obj,
                    description=qtext, answer=answer, marks=0
                )
                q.save()
            elif qtype == 'SHORT':
                # print "descriptive"
Example #4
0
                print(e)

        for question in quiz.findall(question_xpath):
            qtype = question.attrib[tscIQ + 'type']
            qtext = question[0].text
            if qtype == 'MC':
                # print "multiple choice"
                # answer_xpath = ".//" + tscIQ + "correctAnswer"
                answer = int(math.log(int(question[1].text), 2))
                options = json.dumps([
                    opt.text
                    for opt in question.findall(".//" + tscIQ + "answer")
                ])
                q = SingleChoiceQuestion(quiz=quiz_obj,
                                         question_module=qmodule_obj,
                                         description=qtext,
                                         options=options,
                                         answer=answer,
                                         marks=1)
                q.save()
            elif qtype == 'FITB':
                # print "fixed answer"
                answer = json.dumps([
                    ans.text
                    for ans in question.findall(".//" + tscIQ + "answer")
                ])
                q = FixedAnswerQuestion(quiz=quiz_obj,
                                        question_module=qmodule_obj,
                                        description=qtext,
                                        answer=answer,
                                        marks=0)
                q.save()