def record_feedback(request): json_dict = json.loads(request.body.decode('utf-8')) stars = json_dict['stars'] text = json_dict['text'] subject_feedback = request.session['subject'] print("Rating " + stars) print("Feedback " + text) if(text != None or stars != None): fed = dbRoutine.create_feedback(text, stars) dbRoutine.link_feedback(fed,subject_feedback) return JsonResponse({'record_score':'success'})
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)