Ejemplo n.º 1
0
    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:
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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:
Ejemplo n.º 4
0
    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)