Ejemplo n.º 1
0
def record_score(request):
    current_user = request.user
    dbUser = dbRoutine.retrieve_account_no_password(current_user)
#            session1 = dbRoutine.create_session(request.session['subject'], request.session['score'])

    session1 = dbRoutine.create_session(request.session['subject'], request.session['score'],request.session['numques'])
    dbRoutine.link_session(dbUser.getName(), session1)
    
    return JsonResponse({'record_score':'success'})
Ejemplo n.º 2
0
 def test_link_session(self):
     
     acc = "acc"
     pwd = "pwd"
     dbRoutine.create_account(acc, pwd)
     account = dbRoutine.retrieve_account(acc, pwd)
     dbRoutine.create_fc("biology", "q", "a")
     session = dbRoutine.create_session("biology", 17)
     dbRoutine.link_session(account.getName(), session)
     sessions = account.getSessions()
     
     self.assertEqual(1, sessions.count())
Ejemplo n.º 3
0
def quiz(request):

    if request.is_ajax():
        
        signal = request.POST['signal']
        print("Received AJAX " + signal)
                
        response = "Problem"
        if signal == 'get' :
            
            if request.session['flashcards']:
                card = request.session['flashcards'].pop()
                request.session['numques']+=1
                request.session.modified = True
                response = { "signal" : card }              
            else:              
                response ={ "signal" : 'done'}
            
        elif signal == 'right':
            request.session['score']+=1
            response = { "signal" : 'OK'}
            
        elif signal == 'wrong':
            #request.session['card_list'].next()
            response =  { "signal" : "OK"}
            
        elif signal == 'feedback':
            stars = request.POST['stars']
            text = request.POST['text']
            subject_feedback = request.session['subject']
                        
            if(text != None or stars != None):
                fed = dbRoutine.create_feedback(text, stars)
                dbRoutine.link_feedback(fed,subject_feedback)
        
            response =  { "signal" : "OK"}
            
        elif signal == 'end':
            print("End quiz.")
            
            current_user = request.user
            dbUser = dbRoutine.retrieve_account_no_password(current_user)
#            session1 = dbRoutine.create_session(request.session['subject'], request.session['score'])

            session1 = dbRoutine.create_session(request.session['subject'], request.session['score'],request.session['numques'])
            dbRoutine.link_session(dbUser.getName(), session1)
            print("this is request")
            response = {'signal' : request.session['score']}

        return JsonResponse(response)
        

    elif request.POST:          
        subject = request.POST['subject']    
               
        request.session['subject'] = subject
        request.session['score'] = 0
        request.session['numques'] = 0
        request.session['flashcards'] = [entry for entry in dbRoutine.retrieve_fc(subject).values()]
        
        
        print(request.session['flashcards'])

         
        if request.user.is_authenticated():
            current_user = request.user
            logged_in = 1
        else:
            current_user = request.user
            logged_in = 0
        context = {'subject':  request.POST['subject'], 'current_user':current_user, 'logged_in':logged_in }
        return render(request, 'quiz.html', context)