예제 #1
0
    def dispatch(self, request, *args, **kwargs):
        user_examination_question_log_id = kwargs.get('user_examination_question_log_id')

        user_examination = self.get_user_examination()

        if user_examination.started_at is None:
            user_examination.start()

        if user_examination_question_log_id is None:
            next_log_id = UserExaminationQuestionLog.get_next_id(user_examination=user_examination)

            if next_log_id is None:
                user_examination.finish()
                messages.success(request, 'Тестирование %s завершено.' % user_examination.examination.name)
                redirect_to = redirect(reverse('user_examination_list_view'))
            else:
                redirect_to = redirect(reverse(user_examination_process_view, args=[user_examination.id, next_log_id]))

            return redirect_to

        if datetime.datetime.now() > user_examination.must_finished_at:
            user_examination.finish()
            messages.success(request, 'Тестирование %s завершено. Закончилось время.' % user_examination.examination.name)
            return redirect(reverse('user_examination_list_view'))

        user_examination_question_log = self.get_user_examination_question_log()
        if user_examination_question_log.user_examination_answer_logs.exists():
            return redirect(reverse(user_examination_process_view, args=[user_examination.id]))

        if user_examination_question_log.started_at is None:
            user_examination_question_log.started_at = datetime.datetime.now()
            user_examination_question_log.save()

        return super(UserExaminationProcessView, self).dispatch(request, *args, **kwargs)
예제 #2
0
    def dispatch(self, request, *args, **kwargs):
        user_examination_question_log_id = kwargs.get('user_examination_question_log_id')

        user_examination = self.get_user_examination()

        if user_examination.started_at is None:
            user_examination.start()

        if user_examination_question_log_id is None:
            next_log_id = UserExaminationQuestionLog.get_next_id(user_examination=user_examination)

            if next_log_id is None:
                if user_examination.get_next_text_question():
                    text_question_id = user_examination.get_next_text_question()
                    redirect_to = redirect((reverse('user_text_answer_create_view', args=[user_examination.id, text_question_id])))
                else:
                    user_examination.finish()
                    messages.success(request, 'Тестирование %s завершено.' % user_examination.examination.name)
                    redirect_to = redirect(reverse('examination_list_view'))
            else:
                redirect_to = redirect(reverse(user_examination_process_view, args=[user_examination.examination_id, next_log_id]))
            return redirect_to

        user_examination_question_log = self.get_user_examination_question_log()
        if user_examination_question_log.user_examination_answer_logs.exists():
            return redirect(reverse(user_examination_process_view, args=[user_examination.examination_id]))

        return super(UserExaminationProcessView, self).dispatch(request, *args, **kwargs)
예제 #3
0
 def get_title(self):
     user_examination = self.get_user_examination()
     return 'Тестирование %s, необходимо закончить до %s, осталось %s мин, осталось вопросов: %s' % (
         user_examination.examination, user_examination.must_finished_at.strftime('%d.%m.%Y %H:%M:%S'),
         user_examination.get_remaining_minutes(), UserExaminationQuestionLog.get_remains_for_user_examination(user_examination)
     )