def save_answer(self):
     user_selected_answers = self.user.studentcondition.current_selected_answers.all(
     )
     if not user_selected_answers:
         return False
     question = user_selected_answers[0].question
     try:
         student_answer = StudentAnswer.objects.create(
             student=self.user,
             question=question,
             test=StudentTest.objects.filter(student=self.user,
                                             closed=False).first())
     except Exception as e:
         print(e)
         text = self.language.student_test_not_found
         self.send_common_message(text, None)
         check_user_status(self, self.main_menu)()
         self.user.studentcondition.current_selected_answers.clear()
         self.user.studentcondition.save()
         return False
     for selected_answer in user_selected_answers:
         student_answer.answers.add(selected_answer)
     student_answer.save()
     self.user.studentcondition.current_selected_answers.clear()
     self.user.studentcondition.save()
     return True
 def agent_theory(self, page: int):
     test = Test.objects.filter(pk=1).first()
     if not test:
         self.bot.send_message(self.user.user_id, self.language.test_not_found)
         return check_user_status(self, self.main_menu)()
     questions = test.question_set.all()
     if len(questions) == page:
         return self.main_menu()
     question = questions[page]
     text = self.language.theory_wrapper.format(question.category, question.paragraph)
     markup = self.keyboards.generate_keyboard_for_theory_block(page, 'agent')
     self.send_common_message(text, markup)
     return self.user.step
    def agent_test(self, question_num=0):
        test = Test.objects.filter(pk=1).first()
        if not test:
            self.bot.send_message(self.user.user_id, self.language.test_not_found)
            return check_user_status(self, self.main_menu)()

        questions = test.question_set.all()
        if question_num == len(questions):
            return self.complete_test()
        else:
            question = questions[question_num]
        markup = self.keyboards.generate_keyboard_for_test(self.user, question, question_num, 1)
        text = self.language.question_wrapper.format(question_num + 1, question.text, generate_answers_in_message(question.answer_set.all()))

        self.send_common_message(text, markup)
 def checked_question(self, test_num: int, page: int):
     test = None
     test = Test.objects.filter(pk=test_num).first()
     if not test:
         self.bot.send_message(self.user.user_id,
                               self.language.test_not_found)
         return check_user_status(self, self.main_menu)()
     question = test.question_set.all()[page]
     text = self.language.question_wrapper.format(
         page + 1, question.text,
         generate_answers_in_message(question.answer_set.all()))
     markup = self.keyboards.generate_keyboard_for_theory_question(
         test.name, self.user, question, page, test.pk)
     self.send_common_message(text, markup)
     return self.user.step