コード例 #1
0
ファイル: views.py プロジェクト: tlmn95/se2015
    def post(self, request, grade_id, skill_id, format=None):
        skills = Skill.objects.filter(grade__id=grade_id)
        skill = skills.get(id_in_grade=skill_id)

        exercise = Exercise.objects.get(skill=skill, id=request.data.get('id'))

        serializer = ExerciseAnswerSerializer(exercise, data=request.data)

        if serializer.is_valid():
            # Save exercise record
            record = ExerciseRecord(exercise=exercise,
                                    user=request.user.profile)

            string_answer = request.data.get('answer')
            list_answer = string_answer.split('|')

            if self.check_correct_answer(request, exercise):
                record.score = 10
                record.save()
                for _answer in list_answer:
                    user_answer = UserAnswerRecord(exercise_record=record,
                                                   answer=_answer)
                    user_answer.save()
                return Response(True)
            else:
                record.score = 0
                record.save()
                for _answer in list_answer:
                    user_answer = UserAnswerRecord(exercise_record=record,
                                                   answer=_answer)
                    user_answer.save()
                return Response(False)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #2
0
ファイル: views.py プロジェクト: proj5/se2015
 def post(self, request, exam_id, format=None):
     exam = Exam.objects.get(id=exam_id)
     score = 0
     serializer = ExamAnswerSerializer(exam, data=request.data)
     try:
         exam_record = ExamRecord.objects.get(
             exam=exam,
             user=request.user.profile
         )
     except ExamRecord.DoesNotExist:
         exam_record = ExamRecord(
             exam=exam,
             user=request.user.profile
         )
     exam_record.save()
     if serializer.is_valid():
         for exercise in exam.exercises.all():
             _exercises = request.data.get('exercises').split('&')
             for string in _exercises:
                 id = string.split('|', 1)[0]
                 _exercise = string.split('|', 1)[1]
                 if id == str(exercise.id):
                     if self.check_correct_answer(_exercise,
                        exercise):
                         exercise_score = 1
                     else:
                         exercise_score = 0
                     score += exercise_score
                     exercise_record = ExerciseRecord(
                         exercise=exercise,
                         exam_record=exam_record,
                         user=request.user.profile,
                         score=exercise_score
                     )
                     exercise_record.save()
                     for answer in _exercise.split('|'):
                         user_answer_record = UserAnswerRecord(
                             exercise_record=exercise_record,
                             answer=answer
                         )
                         user_answer_record.save()
         # Save exam record
         exam_record.done_time = request.data.get('done_time')
         exam_record.score = score
         exam_record.save()
         return Response(score)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #3
0
ファイル: views.py プロジェクト: tlmn95/se2015
 def post(self, request, exam_id, format=None):
     exam = Exam.objects.get(id=exam_id)
     score = 0
     serializer = ExamAnswerSerializer(exam, data=request.data)
     try:
         exam_record = ExamRecord.objects.get(exam=exam,
                                              user=request.user.profile)
     except ExamRecord.DoesNotExist:
         exam_record = ExamRecord(exam=exam, user=request.user.profile)
     exam_record.save()
     if serializer.is_valid():
         for exercise in exam.exercises.all():
             _exercises = request.data.get('exercises').split('&')
             for string in _exercises:
                 id = string.split('|', 1)[0]
                 _exercise = string.split('|', 1)[1]
                 if id == str(exercise.id):
                     if self.check_correct_answer(_exercise, exercise):
                         exercise_score = 1
                     else:
                         exercise_score = 0
                     score += exercise_score
                     exercise_record = ExerciseRecord(
                         exercise=exercise,
                         exam_record=exam_record,
                         user=request.user.profile,
                         score=exercise_score)
                     exercise_record.save()
                     for answer in _exercise.split('|'):
                         user_answer_record = UserAnswerRecord(
                             exercise_record=exercise_record, answer=answer)
                         user_answer_record.save()
         # Save exam record
         exam_record.done_time = request.data.get('done_time')
         exam_record.score = score
         exam_record.save()
         return Response(score)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #4
0
ファイル: views.py プロジェクト: proj5/se2015
    def post(self, request, grade_id, skill_id, format=None):
        skills = Skill.objects.filter(grade__id=grade_id)
        skill = skills.get(id_in_grade=skill_id)

        exercise = Exercise.objects.get(skill=skill, id=request.data.get('id'))

        serializer = ExerciseAnswerSerializer(exercise, data=request.data)

        if serializer.is_valid():
            # Save exercise record
            record = ExerciseRecord(
                exercise=exercise,
                user=request.user.profile
            )

            string_answer = request.data.get('answer')
            list_answer = string_answer.split('|')

            if self.check_correct_answer(request, exercise):
                record.score = 10
                record.save()
                for _answer in list_answer:
                    user_answer = UserAnswerRecord(
                        exercise_record=record,
                        answer=_answer
                    )
                    user_answer.save()
                return Response(True)
            else:
                record.score = 0
                record.save()
                for _answer in list_answer:
                    user_answer = UserAnswerRecord(
                        exercise_record=record,
                        answer=_answer
                    )
                    user_answer.save()
                return Response(False)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)