示例#1
0
 def accessibility_view(self):
     category = self._secure_get_category(int(self.request.matchdict['id']))
     
     if self.request.params.get('nojs','0') != '1':
         if not self.request.user.needs_accessibility:
             return HTTPFound(location=route_url('category', self.request))
 
     id = self.request.user.current_test
     test = Tests.by(id).first()
     results = TestsResults.by({'tests_id':id}, sort='id asc').all()
 
     if 'form.submit' in self.request.params:
         for key, value in self.request.params.iteritems():
             key_type, sep, rid = key.rpartition(".")
             if key_type == 'question':
                 result = TestsResults.by(rid).first()
                 passed = TestManager.check_answer_byid(result.question_sets_id, int(value))
                 result.correctly_answered = passed
                 if not passed:
                     result.wrong_attempts = test.max_wrong_answer_allowed
                 result.attempted = True
                 result.duration = self._accessibility_duration_calculator(self.request.params['st'], len(results), test.question_time_allowed)
                 final = self._test_calculator(test,results,result)
         transaction.commit()
         return HTTPFound(location=route_url('score', self.request, id=id))
     else:
         self.response['time_started'] = int(time.time())
         self.response['test'] = test
         self.response['results'] = []
         for result in results:
             self.response['results'].append({'question_set': result,
                                              'answer': result.get_answers()})
         return self.template('playing-accessibility.pt')
示例#2
0
    def check(self):
    
        self.response['was_correct'] = -1
        category = self._secure_get_category(int(self.request.matchdict['id']))
        
        if 'answer' in self.request.params:
            answer = self.request.params.get('answer','0')
            duration = float(self.request.params['time'])
            self.response['was_correct'] = TestManager.check_answer_byid(self.request.user.current_question, answer)
            
            result = TestsResults.by({'tests_id':self.request.user.current_test, 'question_sets_id':self.request.user.current_question}).first()
            self.log_if_error('Current Test: %d' % self.request.user.current_test)
            self.log_if_error('Current Question: %d' % self.request.user.current_question)
            self.log_if_error('Chosen Answer: %s' % answer)
            self.log_if_error('Duration: %s' % duration)
            test = Tests.by(self.request.user.current_test).first()

            if not self.response['was_correct'] and duration > 0:
                if result.wrong_attempts < test.max_wrong_answer_allowed:
                    result.wrong_attempts += 1
                    duration = duration - test.wrong_answer_time_penalty
            
            # cheaters hacking more than duration will result in failure
            if duration <= 0 or duration > test.question_time_allowed:
                duration = 0

            self.response['continue_on'] = True
            if result.wrong_attempts == test.max_wrong_answer_allowed or self.response['was_correct'] or duration == 0:
                self.response['continue_on'] = False
                
            result.correctly_answered = self.response['was_correct']
            result.duration = duration
            answers = result.get_answers()
            changed = []
            for a in answers:
                if a['id'] == int(answer):
                    checked = -1
                    if self.response['was_correct']:
                        checked = 1
                    changed.append({'id':a['id'],'content':a['content'],'answered':checked})
                else:
                    changed.append(a)
            result.set_answers(changed)
            transaction.commit()
            
        self.response['duration'] = int(duration)
        return self.response