def on_get(self): #if an argument is passed then the test should be comprised of questions of a specific section sid = self.get_argument("sid", None) #Create new mock test object try: if sid: try: t = PractiseTest.objects(user=str(self.current_user.id), is_completed=False, cursor__ne=0).get() self.base_render("test/test.html", test=t, timed=False, existing=True) return except DoesNotExist, e: t = PractiseTest() timed = False questions = [ question for question in Question.objects(sid=sid) ] #Get questions related to that section shuffle(questions) questions = questions[:PRACTISE_TEST_SIZE] else:
def on_get(self): #if an argument is passed then the test should be comprised of questions of a specific section sid = self.get_argument("sid", None) #Create new mock test object try: if sid: try: t = PractiseTest.objects(user=str(self.current_user.id), is_completed=False, cursor__ne=0).get() self.base_render("test/test.html", test=t, timed=False, existing=True) return except DoesNotExist, e: t = PractiseTest() timed = False questions = [question for question in Question.objects(sid=sid)] #Get questions related to that section shuffle(questions) questions = questions[:PRACTISE_TEST_SIZE] else:
def on_post(self): try: question = self.get_argument("question-inp", None) option1 = self.get_argument("option1-inp", None) option2 = self.get_argument("option2-inp", None) option3 = self.get_argument("option3-inp", None) option4 = self.get_argument("option4-inp", None) correct = [self.get_argument("0", None), self.get_argument("1", None),self.get_argument("2", None),self.get_argument("3", None)] type = self.get_argument("type", None) if type == "main": q = Question() elif type == "mini": q = MiniQuizQuestion() q.question = question q.options = [option1, option2, option3, option4] q.answer = [answer for answer in correct if answer != None] q.save() except Exception, e: print e