예제 #1
0
파일: ppc.py 프로젝트: zahidmitha/web-app
    def on_get(self):
        try:
            hpc = HazardPerceptionClip.objects
            if self.current_user:
                hpt = HazardPerceptionTest.objects(
                    uid=str(self.current_user.id))

                scores = {}
                for test in hpt:
                    if str(test.id) not in scores:
                        scores[str(test.id)] = test.score
                    else:
                        if scores[str(test.id)] < test.score:
                            scores[str(test.id)] = test.score
                    scores[str(test.cid)] = test.score
            else:
                scores = {}

            self.base_render("ppc/learn-hazard-two-clicks.html",
                             clips=hpc,
                             has_seen=scores.keys(),
                             older_scores=scores)
        except Exception, e:
            print e
            self.log.info("No hazard perception clips were found")
            self.base_render("ppc/learn-hazard-two-clicks.html", clips=None)
예제 #2
0
파일: user.py 프로젝트: intheory/web-app
    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)
예제 #3
0
파일: user.py 프로젝트: intheory/web-app
 def wrapper(self, *args, **kwargs):
     from app.handlers.ppc import GetClipPageHandler
     try:
         if self.current_user and self.current_user['has_paid']:
             return method(self, *args, **kwargs)
         elif isinstance(self, GetClipPageHandler):
             #if this is the first time a user requests a new HAZARD test and the user has not reached the limit allow it
             return method(self, *args, **kwargs)
         elif isinstance(self, GetClipPageHandler) and self.current_user and len(HazardPerceptionTest.objects(uid=str(self.current_user.id))) < 2:
             #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)
예제 #4
0
파일: user.py 프로젝트: zahidmitha/web-app
 def wrapper(self, *args, **kwargs):
     from app.handlers.ppc import GetClipPageHandler
     try:
         if self.current_user and self.current_user['has_paid']:
             return method(self, *args, **kwargs)
         elif isinstance(self, GetClipPageHandler):
             #if this is the first time a user requests a new HAZARD test and the user has not reached the limit allow it
             return method(self, *args, **kwargs)
         elif isinstance(self,
                         GetClipPageHandler) and self.current_user and len(
                             HazardPerceptionTest.objects(
                                 uid=str(self.current_user.id))) < 2:
             #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)
예제 #5
0
파일: user.py 프로젝트: zahidmitha/web-app
    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)
예제 #6
0
파일: learn.py 프로젝트: intheory/web-app
    def on_get(self):
        try:
            hpc = HazardPerceptionClip.objects

            if self.current_user:
                hpt = HazardPerceptionTest.objects(uid=str(self.current_user.id))

                scores = {}
                for test in hpt:
                    if str(test.id) not in scores: 
                        scores[str(test.id)] = test.score
                    else:
                        if scores[str(test.id)] < test.score:
                            scores[str(test.id)] = test.score
                    scores[str(test.cid)] = test.score
            else:
                scores = {}
            
            self.base_render("learn/learn-hazard.html", clips=hpc, has_seen=scores.keys(), older_scores=scores)
        except Exception, e:
            self.log.info("No hazard perception clips were found")
            self.base_render("learn/learn-hazard.html", clips=None)