def sn(request): user="" pwd="" form = account(request.POST or None) if form.is_valid(): user = form.cleaned_data['username'] pwd = form.cleaned_data['password'] user = user.lower(); try: listing = dbRoutine.retrieve_account_no_password(user) except dbRoutine.retrieve_account_no_password(user).DoesNotExist: listing = None if (listing == None): dbRoutine.create_account(user, pwd) user_account = User.objects.create_user(user, "", pwd) user_account_login = authenticate(username=user, password=pwd) login(request, user_account_login) return HttpResponseRedirect('/../home') else: return HttpResponseRedirect('/../welcome/accountexists') context={ "form": form, } return render(request, 'signup.html', context)
def test_retrieve_account_no_password(self): acc = "acc" pword = "pwd" dbRoutine.create_account(acc, pword) account = dbRoutine.retrieve_account_no_password(acc) self.assertEqual("acc", account.getName()) wrong_acc = "wrong" account = dbRoutine.retrieve_account_no_password(wrong_acc) self.assertEqual(None, account )
def viewcards(request): # subject = request.POST['subject'] if request.user.is_authenticated(): current_user = request.user logged_in = 1 subject = request.POST['subject'] # get the cards dbUser = dbRoutine.retrieve_account_no_password(current_user) #cards = dbUser.getCards() #cards = dbRoutine.retrieve_fc2(subject) cards = dbRoutine.retrieve_fc(subject) if (cards.count() == 0): valid_cards = 0 else: valid_cards = 1 return render(request, 'viewcards.html', {'current_user':current_user, 'subject':subject, 'logged_in':logged_in, 'cards':cards,'valid_cards':valid_cards}) else: current_user = request.user logged_in = 0 cards = None valid_cards = -1 return render_to_response('needacc.html')
def viewsessions(request): if request.user.is_authenticated(): current_user = request.user logged_in = 1 # get the sessions dbUser = dbRoutine.retrieve_account_no_password(current_user) sessions = dbUser.getSessions() if (sessions.count() == 0): valid_sessions = 0 else: valid_sessions = 1 return render_to_response('viewsessions.html', {'current_user':current_user, 'logged_in':logged_in, 'sessions':sessions, 'valid_sessions':valid_sessions}) else: current_user = request.user logged_in = 0 return render_to_response('needacc.html')
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'})
def register(request): print ("register" + request) json_dict = json.loads(request.body.decode('utf-8')) user = json_dict['username'] pwd = json_dict['password'] try: listing = dbRoutine.retrieve_account_no_password(user) except dbRoutine.retrieve_account_no_password(user).DoesNotExist: listing = None if (listing == None): dbRoutine.create_account(user, pwd) user_account = User.objects.create_user(user, "", pwd) user_account_login = authenticate(username=user, password=pwd) login(request, user_account_login) return JsonResponse({'registration':'successful'}) else: return JsonResponse({{'registration':'duplicate'}})
def take_quiz(request): subject_list_all = Subject.objects.values_list('name', flat=True) if request.user.is_authenticated(): current_user = request.user logged_in = 1 dbUser = dbRoutine.retrieve_account_no_password(current_user) subject_list = dbUser.getSubjects() else: current_user = request.user logged_in = 0 subject_list = None context = {'subject_list': subject_list, 'subject_list_all': subject_list_all , 'current_user':current_user, 'logged_in':logged_in } return render(request, 'take_quiz.html', context)
def new_card(request): json_dict = json.loads(request.body.decode('utf-8')) subject = json_dict['subject'] question = json_dict['question'] answer = json_dict['answer'] subject.lower().title() card = dbRoutine.create_fc(subject, question, answer) current_user = request.user dbUser = dbRoutine.retrieve_account_no_password(current_user) dbRoutine.link_card(dbUser.getName(), card) dbRoutine.link_subject(dbUser.getName(), subject) return JsonResponse({'new_card':'success'})
def index(request): sub="" que="" ans="" form = CreateForm(request.POST or None) if form.is_valid(): sub = form.cleaned_data['subject'] que = form.cleaned_data['question'] ans = form.cleaned_data['answer'] sub.lower(); card = dbRoutine.create_fc(sub, que, ans) current_user = request.user dbUser = dbRoutine.retrieve_account_no_password(current_user) dbRoutine.link_card(dbUser.getName(), card) dbRoutine.link_subject(dbUser.getName(), sub) cards = dbUser.getCards() print (cards.count()) return HttpResponseRedirect('createMore/') #=========================================================================== # allSubjects = Subject.objects.all(); # # subjectData = { # "sub_detail" : allSubjects # } #=========================================================================== if request.user.is_authenticated(): current_user = request.user logged_in = 1 else: current_user = request.user logged_in = 0 context={ "form": form, "current_user": current_user, "logged_in": logged_in } return render(request, 'create.html', context)
def index(request): subject_list = Subject.objects.values_list('name', flat=True) subject_list2 = None subject_listpub = None valid_subject_list2 = 1 if request.user.is_authenticated(): current_user = request.user dbUser = dbRoutine.retrieve_account_no_password(current_user) subject_list2 = dbUser.getSubjects(); print(subject_list2) if (subject_list2.count() == 0): valid_subject_list2 = 0 print(subject_list2) subject_listpub = dbRoutine.retrieve_publicSub() logged_in = 1 else: current_user = request.user logged_in = 0 return render(request, 'home.html', {'valid_subject_list2':valid_subject_list2, 'current_user':current_user, 'logged_in':logged_in, 'subject_list':subject_list, 'subject_list2':subject_list2, 'subject_listpub':subject_listpub})
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)