Пример #1
0
 def _generate_test(self):
     category = Categories.by(self.category_id).first()
     last_test = Tests.by({'category':category.name, 'alias':self.alias},sort='id desc').first()
     
     # Create New Test
     test = Tests(alias=self.alias, category=category.name, d2l_folder=category.d2l_folder, used_accessibility_view=self.used_accessibility_view)
     # Copy values at time of generation, this in case values change in the future, personal results aren't effected.
     test.wrong_answer_time_penalty = category.wrong_answer_time_penalty
     test.max_wrong_answer_allowed = category.max_wrong_answer_allowed
     test.question_time_allowed = category.question_time_allowed
     DBSession.add(test)
     DBSession.flush()
     
     # Get and Randomize Questions
     questionsets = QuestionSets.by({'category_id':self.category_id}).all()
     random.shuffle(questionsets) # randomize first to guarentee all questions
     questionsets = questionsets[0:category.playable_questions] # limit randomized
     
     # Setup Unfinished Questions
     for questionset in questionsets:
         question = self._get_question_variation(questionset, last_test)
         
         result = TestsResults(tests_id=test.id, 
                               question_sets_id=questionset.id, 
                               question=question,
                               answer_choices=TestManager.get_answers(questionset.id)
                               )
         DBSession.add(result)
         
     
     # okay below
     DBSession.flush()
     user = Users.by({'alias':self.alias}).first()
     user.current_test = test.id
     transaction.commit()