def wrapper(self, *args, **kwargs): from app.handlers.learn import ViewSectionHandler, GetClipPageHandler from app.handlers.test import CreateNewTestHandler try: if self.current_user and self.current_user['has_paid']: return method(self, *args, **kwargs) elif isinstance(self, ViewSectionHandler) and self.current_user and len(self.current_user['cursors'].keys()) < self.settings['sections_limit']: #if the request is to see a new section and the user has not reached the limit allow it return method(self, *args, **kwargs) elif isinstance(self, CreateNewTestHandler) and self.current_user: practice_limit = False mock_limit = False #if the request is to start a new practice test and the user has not reached the limit allow it if len(PractiseTest.objects(user=str(self.current_user.id))) >= self.settings['practice_tests_limit']: practice_limit = True if len(MockTest.objects(user=str(self.current_user.id))) >= self.settings['mock_tests_limit']: mock_limit = True if mock_limit or practice_limit: self.redirect("/payment") else: return method(self, *args, **kwargs) elif isinstance(self, GetClipPageHandler) and self.current_user and len(HazardPerceptionTest.objects(uid=str(self.current_user.id))) < self.settings['clips_limit']: #if the request is to start a new HAZARD test and the user has not reached the limit allow it return method(self, *args, **kwargs) else: #else redirect them to the payment page self.redirect("/payment") except Exception, e: raise tornado.web.HTTPError(403)
def on_get(self): if not self.current_user: self.base_render("home.html") else: uid = self.current_user.id u = User.objects(id=uid).get() history = MockTest.objects(user=str(uid)) #TODO: create a model for user's history self.redirect("/dashboard")
def wrapper(self, *args, **kwargs): from app.handlers.learn import ViewSectionHandler, GetClipPageHandler from app.handlers.test import CreateNewTestHandler try: if self.current_user and self.current_user['has_paid']: return method(self, *args, **kwargs) elif isinstance(self, ViewSectionHandler) and self.current_user and len( self.current_user['cursors'].keys( )) < self.settings['sections_limit']: #if the request is to see a new section and the user has not reached the limit allow it return method(self, *args, **kwargs) elif isinstance(self, CreateNewTestHandler) and self.current_user: practice_limit = False mock_limit = False #if the request is to start a new practice test and the user has not reached the limit allow it if len(PractiseTest.objects(user=str(self.current_user.id)) ) >= self.settings['practice_tests_limit']: practice_limit = True if len(MockTest.objects(user=str(self.current_user.id)) ) >= self.settings['mock_tests_limit']: mock_limit = True if mock_limit or practice_limit: self.redirect("/payment") else: return method(self, *args, **kwargs) elif isinstance(self, GetClipPageHandler) and self.current_user and len( HazardPerceptionTest.objects( uid=str(self.current_user.id)) ) < self.settings['clips_limit']: #if the request is to start a new HAZARD test and the user has not reached the limit allow it return method(self, *args, **kwargs) else: #else redirect them to the payment page self.redirect("/payment") except Exception, e: raise tornado.web.HTTPError(403)
#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: t = MockTest() questions = [question for question in Question.objects] shuffle(questions) questions = questions[:MOCK_TEST_SIZE] timed = True t.user = str(self.current_user.id) t.questions = questions t.score = 0 t.cursor = 0 t.save() self.base_render("test/test.html", test=t, timed=timed) except Exception, e:
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: t = MockTest() questions = [question for question in Question.objects] shuffle(questions) questions = questions[:MOCK_TEST_SIZE] timed = True t.user = str(self.current_user.id) t.questions = questions t.score = 0 t.cursor = 0 t.save() self.base_render("test/test.html", test=t, timed=timed) except Exception, e: