Ejemplo n.º 1
0
def honorcode(request, exam_code):    
    parameters = {}    
    exam_obj = ExammodelApi()
    user_profile_obj = UserProfile()
    h_a_s = HonorCodeAcceptSingal()     
    ess = ExamStartSignal()       
    user = user_profile_obj.get_user_by_username(request.user.username)
    exam_details = exam_obj.find_one_exammodel({'exam_code':int(exam_code)})
    subscribed = user_profile_obj.check_subscribed(request.user.username, exam_code)
    current_time = time.mktime(datetime.datetime.now().timetuple())

    if request.user.is_authenticated() and subscribed:
        if exam_details['exam_family'] =='DPS': 
            return HttpResponseRedirect('/dps/' + str(exam_code) + '/')
            
        current_time = time.mktime(datetime.datetime.now().timetuple())
        if current_time - exam_details['exam_date'] > exam_details['exam_duration']*60:
            return HttpResponseRedirect('/results/' + str(exam_code))

        if_cps_ended = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':0,'end':1}) 
        if if_cps_ended != None:
            return HttpResponseRedirect('/results/' + str(exam_code) + '/')        

        elif exam_details['exam_family'] =='CPS': 
            if current_time < exam_details['exam_date']:
                parameters['render_before_exam'] = True

            elif current_time > exam_details['exam_date']:
                parameters['render_before_exam'] = False            
            
            # if current_time - int(exam_details['exam_date']) > int(exam_details['exam_duration'])*60:
            #     return HttpResponseRedirect('/results/' + str(exam_code) +'/')

        
        exam_details['exam_date'] = datetime.datetime.fromtimestamp(int(exam_details['exam_date']))
        validate_start = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':1})
        if validate_start != None:
            h_a_s_accepted = h_a_s.check_honor_code_accepted({
                'exam_code':int(exam_code), 
                'useruid':request.user.id,
                'accept':1,
                'ess_time':validate_start['start_time']})
        else:
            h_a_s_accepted = None

        if h_a_s_accepted == None:
            parameters['exam_code'] = exam_code 
            parameters['user'] = user
            parameters['exam_details'] = exam_details
            
            
            return render_to_response('exam_tips_and_honor_code.html', parameters, context_instance=RequestContext(request))
        else:
            return HttpResponseRedirect('/cps/' + str(exam_code)+'/')
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 2
0
def results(request, exam_code):
    parameters ={}
    res={}
    res['exam_code'] = int(exam_code)    
    exam_obj = ExammodelApi()
    exam_details = exam_obj.find_one_exammodel({'exam_code':int(exam_code)})
    res['exam_details'] = exam_details
    ess = ExamStartSignal()            
    ess_check = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id})

    question_obj = QuestionApi()    
    total_questions = question_obj.get_count({"exam_code": int(exam_code), 'marks':1})

    ans = AttemptedAnswerDatabase()
    try:
        all_ans = ans.find_all_atttempted_answer({
            'exam_code':int(exam_code), 
            'user_id':request.user.id,
            'ess_time':ess_check['start_time']
            }, fields={'q_no':1, 'attempt_details':1})
    except:
        all_ans = ''
    answer_list = ''
    anss = []
    for eachAns in all_ans:
        anss.append(eachAns['q_no'])
    for i in range(0,total_questions):       
        try:
            if i in anss:
                answer_list += all_ans[anss.index(i)]['attempt_details'][0]['selected_ans']
            else:
                answer_list +='e'
        except:
            answer_list += 'e'
    exam_handler = ExamHandler()    
    score_dict = exam_handler.check_answers(exam_code, answer_list)
    user_profile_obj = UserProfile()
    user = user_profile_obj.get_user_by_username(request.user.username)
    parameters['user'] = user            
    parameters['result'] = score_dict
    parameters['exam_code'] = exam_code
    parameters['myrankcard'] = {'total':200, 'rank':1}
    return render_to_response('results.html', parameters, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def get_upcoming_exams(request):
    '''
    the function returns api of upcoming exams
    '''
    if request.user.is_authenticated():
        exam_handler = ExamHandler()
        upcoming_exams = exam_handler.list_upcoming_exams()
        for eachExam in upcoming_exams:
            user_obj = UserProfile()
            subscription_status = user_obj.check_subscribed(
                request.user.username, eachExam['exam_code'])
            eachExam['subscribed'] = 1 if subscription_status else 0

        return HttpResponse(
            json.dumps({
                'status': 'ok',
                'result': upcoming_exams
            }))
    else:
        return HttpResponse(
            json.dumps({
                'status': 'error',
                'message': 'Not a valid request'
            }))
Ejemplo n.º 4
0
 def save_category(self, request):
     user = UserProfile()
     if request.user.is_authenticated():
         ioe_check = bool(request.POST.get('ioe_check', ''))
         iom_check = bool(request.POST.get('iom_check', ''))
         if ioe_check and iom_check:
             cat = 'IDP'
         elif ioe_check:
             cat = 'BE-IOE'
         elif iom_check:
             cat = 'MBBS-IOM'
         user.update_upsert({'username': request.user.username}, {
             'student_category': cat,
             'student_category_set': 1
         })
         return HttpResponse(json.dumps({'status': 'ok'}))
     else:
         return HttpResponse(
             json.dumps({
                 'status':
                 'error',
                 'message':
                 'You are not authorized to perform this action.'
             }))
Ejemplo n.º 5
0
def get_question_set(request, exam_code):
    '''
    the function returns the api of a model question
    '''
    if request.user.is_authenticated():
        coupon_code = request.POST.get('coupon')
        user_obj = UserProfile()
        from apps.mainapp.classes.Exams import Exam
        exam_obj = Exam()

        up_exm = exam_obj.get_exam_detail(int(exam_code))
        if up_exm['exam_family'] == 'CPS':
            if time.mktime(
                    datetime.datetime.now().timetuple()) < up_exm['exam_date']:
                return HttpResponse(
                    json.dumps({
                        'status':
                        'error',
                        'message':
                        'Exam has not begin yet, please check back later.'
                    }))

        coupon_obj = Coupon()
        user_profile_obj = UserProfile()
        subscription_status = user_obj.check_subscribed(
            request.user.username, exam_code)
        user = user_profile_obj.get_user_by_username(request.user.username)
        '''Validation for subscription here'''
        if subscription_status or int(exam_code) in user['valid_exam']:
            exam_handler = ExamHandler()
            model_question_set = exam_handler.get_questionset_from_database(
                exam_code)

            if len(model_question_set) > 0:
                return HttpResponse(
                    json.dumps({
                        'status': 'ok',
                        'result': model_question_set
                    }))
            else:
                return HttpResponse(
                    json.dumps({
                        'status': 'error',
                        'message': 'No question in this exam right now.'
                    }))

        if coupon_obj.validate_coupon(coupon_code, up_exm['exam_category'],
                                      up_exm['exam_family']) is True:

            user_profile_obj = UserProfile()
            user_profile_obj.change_subscription_plan(request.user.username,
                                                      coupon_code)
            #save the coupon code in user's couponcode array
            coupon_obj.change_used_status_of_coupon(coupon_code,
                                                    request.user.username)
            user_profile_obj.save_coupon(request.user.username, coupon_code)

            subscription_status = user_obj.check_subscribed(
                request.user.username, exam_code)
            if subscription_status:
                '''Add Validation for subscription here'''
                exam_handler = ExamHandler()
                model_question_set = exam_handler.\
                    get_questionset_from_database(exam_code)

                response = HttpResponse(
                    json.dumps({
                        'status': 'ok',
                        'result': model_question_set
                    }))
            else:
                response = HttpResponse(
                    json.dumps({
                        'status':
                        'error',
                        'message':
                        'You are not subscribed for this exam'
                    }))
        else:
            response = HttpResponse(
                json.dumps({
                    'status': 'error',
                    'message': 'Invalid Coupon Code.'
                }))
    else:
        response = HttpResponse(
            json.dumps({
                'status': 'error',
                'message': 'Not a valid request'
            }))
    return response
Ejemplo n.º 6
0
def subscription(request):
    parameters = {}    
    user_profile_obj = UserProfile()
    user = user_profile_obj.get_user_by_username(request.user.username)
    parameters['user'] = user
    return render_to_response('subscription.html', parameters, context_instance=RequestContext(request))
Ejemplo n.º 7
0
def sign_up_sign_in(request, android_user=False):
    social_account = SocialAccount.objects.get(user__id=request.user.id)
    from apps.mainapp.classes.Userprofile import UserProfile        
    user_profile_object = UserProfile()
    user = user_profile_object.get_user_by_username(request.user.username)
    try:
        valid_exams = user['valid_exam']
    except:
        # valid_exams=[100, 101]
        valid_exams=[]

    try:
        coupons = user['coupons']
    except:
        coupons = []
    try:
        subscription_type = user['subscription_type']
    except:
        subscription_type = []
    try:
        join_time = user['join_time']
    except:
        join_time = datetime.datetime.now()
        join_time = time.mktime(join_time.timetuple())

    try:
        student_category = user['student_category']
    except:
        student_category = 'both'
    try:
        student_category_set = user['student_category_set']
    except:
        student_category_set = 0

    data = {
            'useruid': int(request.user.id), 
            'first_name': social_account.extra_data['first_name'],
            'last_name': social_account.extra_data['last_name'],
            'name':social_account.extra_data['name'],
            'username' : request.user.username,
             "link": social_account.extra_data['link'],
             "id": social_account.extra_data['id'],
             "timezone": social_account.extra_data['timezone'],
             "email": social_account.extra_data['email'],
            "locale": social_account.extra_data['locale'],
            'coupons':coupons,
            'valid_exam':valid_exams,
            'subscription_type':subscription_type,
            'newsletter_freq':'Weekly',
            'join_time':int(join_time),
            'student_category':student_category,
            'student_category_set':student_category_set
    }

    if android_user == True:
        data['android_user'] = True
    else:
        data['android_user'] = False
    try:
        mc_subscribed = user['subscribed_to_mailchimp']            
    except:
        from apps.mainapp.classes.MailChimp import MailChimp
        mc = MailChimp()
        mc.subscribe(data)
        mc_subscribed = True
    data['mc_subscribed'] = mc_subscribed 
    return user_profile_object.update_upsert({'username':request.user.username}, data)
Ejemplo n.º 8
0
def honorcode(request, exam_code):    
    exam_obj = ExammodelApi()
    exam_details = exam_obj.find_one_exammodel({'exam_code':int(exam_code)})
    user_profile_obj = UserProfile()
    subscribed = user_profile_obj.check_subscribed(request.user.username, exam_code)
    parameters = {}
    parameters['render_before_exam'] = False
    if request.user.is_authenticated() and subscribed:
        from apps.mainapp.classes.query_database import ExamStartSignal
        ess = ExamStartSignal()            
        validate_start = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':1})        
        current_time = time.mktime(datetime.datetime.now().timetuple())

        if exam_details['exam_family'] == 'CPS':
            check_time = exam_details['exam_date']
        else:
            if validate_start !=None:
                check_time = validate_start['start_time']
            else:                
                parameters['exam_details'] = exam_details
                parameters['exam_code'] = exam_code                

                user_profile_obj = UserProfile()
                user = user_profile_obj.get_user_by_username(request.user.username)
                parameters['user'] = user                
                return render_to_response('exam_tips_and_honor_code.html', parameters, context_instance=RequestContext(request))

        if (current_time - check_time)>exam_details['exam_duration']*60:
            ''' For now redirect to results page '''
            # parameters['render_after_exam'] = True            
            # return HttpResponseRedirect('/results/' + str(exam_code))
            parameters['exam_details'] = exam_details
            parameters['exam_code'] = exam_code                

            user_profile_obj = UserProfile()
            user = user_profile_obj.get_user_by_username(request.user.username)
            parameters['user'] = user                
            return render_to_response('exam_tips_and_honor_code.html', parameters, context_instance=RequestContext(request))            

        elif ((current_time - check_time) < exam_details['exam_duration']*60) and (current_time > check_time):
            '''render honor code'''
            try:
                if validate_start != None:
                    honor_code_accept = request.session[str(exam_code)]
                    if honor_code_accept == True:
                        return HttpResponseRedirect('/attend-exam/'+ exam_code +'/')
            except:
                pass
            if exam_details['exam_family'] !='DPS':
                exam_details['exam_date'] = datetime.datetime.fromtimestamp(int(exam_details['exam_date'])).strftime('%Y-%m-%d')
            parameters['exam_details'] = exam_details
            parameters['exam_code'] = exam_code                

            user_profile_obj = UserProfile()
            user = user_profile_obj.get_user_by_username(request.user.username)
            parameters['user'] = user
            return render_to_response('exam_tips_and_honor_code.html', parameters, context_instance=RequestContext(request))

        else:
            parameters['render_before_exam'] = True
            exam_details['exam_date'] = datetime.datetime.fromtimestamp(int(exam_details['exam_date'])).strftime('%Y-%m-%d')
            parameters['exam_details'] = exam_details
            # return HttpResponse(json.dumps({'msg':'exam not started'}))
            return render_to_response('exam_tips_and_honor_code.html', parameters, context_instance=RequestContext(request))        
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 9
0
def attend_exam(request,exam_code):
    user_profile_obj = UserProfile()
    subscribed = user_profile_obj.check_subscribed(request.user.username, exam_code)
    if request.user.is_authenticated() and subscribed:
        parameters = {}
        ess = ExamStartSignal()        
        exam_obj = ExammodelApi()

        exam_details = exam_obj.find_one_exammodel({'exam_code':int(exam_code)})
        validate = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':1})
        end_validate = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':1, 'end':1})        

        atte_ans = AttemptedAnswerDatabase()
        all_answers = atte_ans.find_all_atttempted_answer({
            'exam_code':exam_code, 'user_id':int(request.user.id),
            'ess_starttimestamp':int(validate['start_time'])})
        parameters['all_answers'] = json.dumps(all_answers)

        if end_validate !=None:
            if exam_details['exam_family'] == 'CPS':
                return HttpResponseRedirect('/results/' + str(exam_code) +'/')
            else:
                parameters['all_answers'] = []

        else:
            if validate != None:
                time_elapsed = time.mktime(datetime.datetime.now().timetuple()) - validate['start_time']
                if time_elapsed > exam_details['exam_duration']*60 and exam_details['exam_family']=='CPS':
                    return HttpResponseRedirect('/results/' + str(exam_code) +'/')
                elif time_elapsed > exam_details['exam_duration']*60 and exam_details['exam_family']!='CPS':
                    parameters['all_answers'] = []
            exam_details['exam_duration'] = exam_details['exam_duration'] - time_elapsed/60
        
        try:
            honor_code_accept = request.session[str(exam_code)]
        except:
            honor_code_accept = False

        if not honor_code_accept:
            return HttpResponseRedirect('/honorcode/'+str(exam_code) +'/')
        
        question_obj = QuestionApi()    
        questions = question_obj.find_all_questions({"exam_code": int(exam_code)})
        total_questions = question_obj.get_count({"exam_code": int(exam_code)})
        sorted_questions = sorted(questions, key=lambda k: k['question_number'])

        if exam_details['exam_family'] != 'DPS':
            exam_details['exam_date'] = datetime.datetime.fromtimestamp(int(exam_details['exam_date'])).strftime('%Y-%m-%d')

        parameters['questions'] = json.dumps(sorted_questions)
        parameters['exam_details'] = exam_details
        
        start_question_number = 0 
        try:
            start_question_number = int(request.session['current_question_number'])
            if start_question_number == '':
                start_question_number = 0
        except:
            start_question_number = 0 

        if start_question_number == total_questions:
            start_question_number = start_question_number - 1
            parameters['next_to_start'] = sorted_questions[start_question_number]
        else:            
            parameters['next_to_start'] = sorted_questions[0]
        
        parameters['start_question_number'] = start_question_number
        parameters['start_question'] = sorted_questions[start_question_number]
        parameters['max_questions_number'] =  total_questions

        parameters['exam_code'] = exam_code        
        user_profile_obj = UserProfile()
        user = user_profile_obj.get_user_by_username(request.user.username)
        parameters['user'] = user
        return render_to_response('exam_main.html', parameters, context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 10
0
def landing(request):
    if request.user.is_authenticated():
        from apps.exam_api.views import ExamHandler
        exam_handler = ExamHandler()
        upcoming_exams = exam_handler.list_upcoming_exams()
        parameters = {}        
        up_exams = []

        user_profile_obj = UserProfile()
        subscribed_exams = user_profile_obj.get_subscribed_exams(request.user.username)
        user = user_profile_obj.get_user_by_username(request.user.username)
        parameters['user'] = user

        subscription_type = user['subscription_type']

        if len(subscription_type) !=0:
            parameters['subscribed'] = True
        else:
            parameters['subscribed'] = False
        try:
            if user['student_category_set'] == 1:
                parameters['student_category_set'] = True
            else:
                parameters['student_category_set'] = False
        except:
            parameters['student_category_set'] = False
            
        for eachExam in upcoming_exams:            
            up_exm = {}
            
            up_exm['name'] = eachExam['exam_name']
            
            if 'IDP' in subscription_type:
                up_exm['subscribed'] = True

            elif eachExam['exam_category'] in subscription_type:
                up_exm['subscribed'] = True

            else:
                up_exm['subscribed'] = eachExam['exam_code'] in subscribed_exams

            up_exm['code'] = eachExam['exam_code']
            if eachExam['exam_family'] != 'DPS':
                up_exm['exam_time'] = eachExam['exam_time']
                up_exm['exam_date'] = datetime.datetime.fromtimestamp(int(eachExam['exam_date'])).strftime("%A, %d. %B %Y")
            up_exm['exam_category'] = eachExam['exam_category']
            up_exm['exam_family'] = eachExam['exam_family']
            up_exm['image'] = eachExam['image']
            up_exams.append(up_exm)

        parameters['upcoming_exams'] = up_exams
        # print up_exams

        # schedule_obj = Schedules()
        # schedules = schedule_obj.get_upcoming_schedules()
        # up_schedules = []
        # for eachSchedule in schedules:
        #     up_sch = {}
        #     up_sch['name'] = eachSchedule['name']
        #     up_sch['code'] = eachSchedule['code']
        #     up_sch['schedule_time'] = eachSchedule['schedule_time']
        #     up_sch['schedule_category'] = eachSchedule['schedule_category']
        #     up_sch['image'] = eachSchedule['image']
        #     up_sch['schedule_date'] = datetime.datetime.fromtimestamp(int(eachSchedule['schedule_date'])).strftime("%A, %d. %B %Y")
        #     up_schedules.append(up_sch)
        # parameters['upcoming_schedules'] = up_schedules

        rank_card_obj = RankCard()
        rank_card = rank_card_obj.get_rank_card(request.user.id, 'IOMMBBSMODEL000')
        try:
            parameters['rank_card'] = rank_card[0]
        except:
            pass

        score_card_obj = ScoreCard()        
        socre_card = score_card_obj.get_score_card(request.user.id, 'IOMMBBSMODEL000')
        try:
            parameters['socre_card'] = socre_card[0]        
        except:
            pass
        parameters['has_result'] = False
        return render_to_response('dashboard.html',parameters,
                              context_instance=RequestContext(request))
    else:
        return render_to_response('landing.html', context_instance=RequestContext(request))
Ejemplo n.º 11
0
    def validate_coupon(self, request):
        if request.user.is_authenticated():
            coupon_obj = Coupon()
            exam_code = request.POST.get('exam_code', '')
            coupon_code = request.POST.get('coupon_code', '')
            user_profile_obj = UserProfile()
            user = user_profile_obj.get_user_by_username(request.user.username)
            from apps.mainapp.classes.Exams import Exam
            exam_obj = Exam()
            if exam_code != 'subs':
                up_exm = exam_obj.get_exam_detail(int(exam_code))
            else:
                if coupon_obj.has_susbcription_plan_in_coupon(coupon_code):
                    coupon_obj.change_used_status_of_coupon(
                        coupon_code, request.user.username)
                    user_profile_obj.change_subscription_plan(
                        request.user.username, coupon_code)
                    user_profile_obj.save_coupon(request.user.username,
                                                 coupon_code)
                    return HttpResponse(
                        json.dumps({
                            'status': 'ok',
                            'url': '/'
                        }))
                else:
                    return HttpResponse(
                        json.dumps({
                            'status': 'error',
                            'message': 'Invalid Coupon code.'
                        }))

            if coupon_obj.validate_coupon(coupon_code, up_exm['exam_category'],
                                          up_exm['exam_family']) == True:
                #save the coupon code in user's couponcode array
                coupon_obj.change_used_status_of_coupon(
                    coupon_code, request.user.username)
                user_profile_obj.change_subscription_plan(
                    request.user.username, coupon_code)
                user_profile_obj.save_coupon(request.user.username,
                                             coupon_code)

                #Refreshment of user
                user = user_profile_obj.get_user_by_username(
                    request.user.username)
                subscription_type = user['subscription_type']
                #if coupon_code != 'IDP' or 'BE-IOE' or 'MBBS-IOM' then save the exam code in the valid exams
                if 'IDP' not in subscription_type and 'BE-IOE' not in subscription_type and 'MBBS-IOM' not in subscription_type:
                    user_profile_obj.save_valid_exam(request.user.username,
                                                     exam_code)

                if 'IDP' in subscription_type:
                    return HttpResponse(
                        json.dumps({
                            'status': 'ok',
                            'url': '/honorcode/' + exam_code
                        }))

                elif up_exm['exam_category'] in subscription_type:
                    return HttpResponse(
                        json.dumps({
                            'status': 'ok',
                            'url': '/honorcode/' + exam_code
                        }))
                else:
                    subscribed_exams = user_profile_obj.get_subscribed_exams(
                        request.user.username)
                    if int(exam_code) in subscribed_exams:
                        #Check if exam is cps or dps
                        #if exam is cps then return url '/cps/exam_code'
                        #else return  url '/dps/exam_code/'
                        exm_dtls = exam_obj.get_exam_detail(int(exam_code))
                        return HttpResponse(
                            json.dumps({
                                'status':
                                'ok',
                                'url':
                                '/' + exm_dtls['exam_family'].lower() + '/' +
                                exam_code
                            }))
                    else:
                        return HttpResponse(
                            json.dumps({
                                'status': 'error',
                                'message': 'Invalid Coupon code.'
                            }))
            else:
                return HttpResponse(
                    json.dumps({
                        'status': 'error',
                        'message': 'Invalid Coupon code.'
                    }))
        else:
            return HttpResponse(
                json.dumps({
                    'status':
                    'error',
                    'message':
                    'You are not authorized to perform this action.'
                }))
Ejemplo n.º 12
0
def show_result(request, exam_code, subject_name):
    user_profile_obj = UserProfile()
    exam_obj = ExammodelApi()
    subscribed = user_profile_obj.check_subscribed(request.user.username, exam_code)
    exam_details = exam_obj.find_one_exammodel({'exam_code':int(exam_code)})
    parameters = {}
    if request.user.is_authenticated() and subscribed:        
        current_time = time.mktime(datetime.datetime.now().timetuple())
        if exam_details['exam_family'] == 'CPS' and current_time - exam_details['exam_date'] < exam_details['exam_duration']*60:
            return HttpResponseRedirect('/')            
        parameters['exam_details'] = exam_details
        question_obj = QuestionApi()    
        questions = question_obj.find_all_questions({"exam_code": int(exam_code),
            'subject':str(subject_name), 'marks':1})
        total_questions = question_obj.get_count({"exam_code": int(exam_code), 
            'subject':subject_name, 'marks':1})

        sorted_questions = sorted(questions, key=lambda k: k['question_number'])
        try:            
            current_q_no = int(request.GET.get('q',''))
            if current_q_no >= total_questions:
                next_q_no = total_questions-1
            else:
                next_q_no = current_q_no + 1
            if current_q_no <= 0:
                previous_q_no = 0
            else:
                previous_q_no = current_q_no -1
        except:
            current_q_no = 0
            previous_q_no = 0
            next_q_no = 1

        if current_q_no >=total_questions:
            current_q_no = total_questions -1
        if current_q_no <=0:
            current_q_no = 0
        parameters['current_q_no'] = current_q_no
        parameters['question_number'] = questions[current_q_no]['question_number']
        parameters['question'] =  questions[current_q_no]
        parameters['subject'] = subject_name
        parameters['exam_code'] = exam_code
        parameters['next_q_no'] = next_q_no
        parameters['previous_q_no'] = previous_q_no

        ess = ExamStartSignal()            
        ans = AttemptedAnswerDatabase()
        ess_check = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id})
        total_questions = question_obj.get_count({"exam_code": int(exam_code)})

        try:
            query = {'exam_code':int(exam_code), 'user_id':int(request.user.id),
                'ess_time':ess_check['start_time'],'q_no':questions[current_q_no]['question_number']}
            att_ans = ans.find_all_atttempted_answer(query)
            parameters['attempted'] = att_ans[0]['attempt_details'][len(att_ans[0]['attempt_details'])-1]['selected_ans']
        except:
            att_ans = ''
            parameters['attempted'] = ''

        user_profile_obj = UserProfile()
        user = user_profile_obj.get_user_by_username(request.user.username)
        parameters['user'] = user        
        return render_to_response('single-result.html', parameters, context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/')        
Ejemplo n.º 13
0
def distributors(request):
    parameters = {}
    user_profile_obj = UserProfile()
    user = user_profile_obj.get_user_by_username(request.user.username)   
    parameters['user'] = user
    return render_to_response('distributors.html', parameters, context_instance=RequestContext(request))
Ejemplo n.º 14
0
def attend_dps_exam(request,exam_code):
    user_profile_obj = UserProfile()
    subscribed = user_profile_obj.check_subscribed(request.user.username, exam_code)
    if request.user.is_authenticated() and subscribed:
        parameters = {}
        ess = ExamStartSignal()        
        exam_obj = ExammodelApi()
        ess = ExamStartSignal()            

        exam_details = exam_obj.find_one_exammodel({'exam_code':int(exam_code)})
        current_time = time.mktime(datetime.datetime.now().timetuple())

        validate_start = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':1,'end':0})        
        
        if validate_start != None:
            check = validate_start['start_time']
        else:
            ess.update_exam_start_signal({
                'exam_code':int(exam_code), 
                'useruid':request.user.id},{
                'start':1, 
                'start_time':int(time.mktime(datetime.datetime.now().timetuple())),
                'end':0,                
                'end_time':''
                })
            validate_start = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':1,'end':0})        
            check = validate_start['start_time']

        dps_exam_start = exam_details['exam_family']=='DPS' and current_time - check > exam_details['exam_duration']*60
        if current_time - check > exam_details['exam_duration']*60:            
            ess.update_exam_start_signal({
                'exam_code':int(exam_code), 
                'useruid':request.user.id, 
                'start':1},{'end':1,'start':0, 
                'end_time':int(time.mktime(datetime.datetime.now().timetuple()))})
            ess.update_exam_start_signal({
                'exam_code':int(exam_code), 
                'useruid':request.user.id},{
                'start':1, 
                'start_time':int(time.mktime(datetime.datetime.now().timetuple())),
                'end':0,                
                'end_time':''
                })
            validate_start = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':1,'end':0})        
            check = validate_start['start_time']
            

        if current_time - check < exam_details['exam_duration']*60:
            atte_ans = AttemptedAnswerDatabase()
            all_answers = atte_ans.find_all_atttempted_answer({
                'exam_code':int(exam_code), 'user_id':int(request.user.id),
                'ess_time':int(validate_start['start_time'])})
            time_elapsed = time.mktime(datetime.datetime.now().timetuple()) - validate_start['start_time']
            exam_details['exam_duration'] = (exam_details['exam_duration']*60 - time_elapsed)/60

            parameters['all_answers'] = json.dumps(all_answers)                        
            question_obj = QuestionApi()    
            questions = question_obj.find_all_questions({"exam_code": int(exam_code), 'marks':1}, fields={'answer.correct':0})
            total_questions = question_obj.get_count({"exam_code": int(exam_code), 'marks':1})
            sorted_questions = sorted(questions, key=lambda k: k['question_number'])

            parameters['questions'] = json.dumps(sorted_questions)
            parameters['exam_details'] = exam_details
        
            start_question_number = 0 
            cqn = CurrentQuestionNumber()
            current_q_no = cqn.check_current_question_number({
                'exam_code':int(exam_code), 
                'useruid':request.user.id, 
                'ess_time':validate_start['start_time']})
            try:
                start_question_number = current_q_no['cqn']
                if start_question_number == '':
                    start_question_number = 0
            except:
                start_question_number = 0 

            if start_question_number == total_questions:
                start_question_number = start_question_number - 1
                parameters['next_to_start'] = sorted_questions[start_question_number]
            else:            
                parameters['next_to_start'] = sorted_questions[0]
        
            parameters['start_question_number'] = start_question_number
            parameters['start_question'] = sorted_questions[start_question_number]
            parameters['max_questions_number'] =  total_questions

            parameters['exam_code'] = exam_code        
            user_profile_obj = UserProfile()
            user = user_profile_obj.get_user_by_username(request.user.username)
            parameters['user'] = user
            return render_to_response('exam_main.html', parameters, context_instance=RequestContext(request))

    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 15
0
def attend_cps_exam(request, exam_code):
    user_profile_obj = UserProfile()
    subscribed = user_profile_obj.check_subscribed(request.user.username, exam_code)
    if request.user.is_authenticated() and subscribed:
        parameters = {}
        ess = ExamStartSignal()        
        exam_obj = ExammodelApi()
        user_profile_obj = UserProfile()
        question_obj = QuestionApi()    
        h_a_s = HonorCodeAcceptSingal()
        ess = ExamStartSignal()            
        cqn = CurrentQuestionNumber()
        atte_ans = AttemptedAnswerDatabase()
        questions = question_obj.find_all_questions({"exam_code": int(exam_code)}, fields={'answer.correct':0})
        user = user_profile_obj.get_user_by_username(request.user.username)
        exam_details = exam_obj.find_one_exammodel({'exam_code':int(exam_code)})

        if_cps_ended = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':0,'end':1}) 
        if if_cps_ended != None:
            return HttpResponseRedirect('/results/' + str(exam_code) + '/')

        current_time = time.mktime(datetime.datetime.now().timetuple())
        if current_time - exam_details['exam_date'] > exam_details['exam_duration']*60:
            return HttpResponseRedirect('/results/' + str(exam_code))

        validate_start = ess.check_exam_started({'exam_code':int(exam_code), 'useruid':request.user.id, 'start':1,'end':0})
        if validate_start != None:
            h_a_s_accepted = h_a_s.check_honor_code_accepted({
                'exam_code':int(exam_code), 
                'useruid':request.user.id,
                'accept':1,
                'ess_time':validate_start['start_time']})
        else:
            h_a_s_accepted = None

        if h_a_s_accepted == None:
            return HttpResponseRedirect('/honorcode/'+str(exam_code) +'/')

        all_answers = atte_ans.find_all_atttempted_answer({
            'exam_code':int(exam_code), 'user_id':int(request.user.id),
            'ess_time':int(validate_start['start_time'])})
        time_elapsed = time.mktime(datetime.datetime.now().timetuple()) - int(exam_details['exam_date'])
        total_questions = question_obj.get_count({"exam_code": int(exam_code)})
        sorted_questions = sorted(questions, key=lambda k: k['question_number'])

        start_question_number = 0 
        current_q_no = cqn.check_current_question_number({
            'exam_code':int(exam_code), 
            'useruid':request.user.id, 
            'ess_time':validate_start['start_time']})
        try:
            start_question_number = current_q_no['cqn']
            if start_question_number == '':
                start_question_number = 0
        except:
            start_question_number = 0 

        if start_question_number == total_questions:
            start_question_number = start_question_number - 1
            parameters['next_to_start'] = sorted_questions[start_question_number]
        else:           
            parameters['next_to_start'] = sorted_questions[0]
    
        parameters['all_answers'] = json.dumps(all_answers)                        
        parameters['questions'] = json.dumps(sorted_questions)
        exam_details['exam_duration'] = (exam_details['exam_duration']*60 - time_elapsed)/60
        exam_details['exam_date'] = datetime.datetime.fromtimestamp(int(exam_details['exam_date'])).strftime('%Y-%m-%d')
        parameters['exam_details'] = exam_details
        parameters['start_question_number'] = start_question_number
        parameters['start_question'] = sorted_questions[start_question_number]
        parameters['max_questions_number'] =  total_questions
        parameters['exam_code'] = exam_code        
        parameters['user'] = user
        return render_to_response('exam_main.html', parameters, context_instance=RequestContext(request))

    else:
        return HttpResponseRedirect('/')