def secretqa_add(request): # DONE: Get QA Add Working if settings.DEBUG: print("In apps.secretqa.views.secretqa_add") if request.POST: form = QA_EditForm(request.POST) if form.is_valid(): if settings.DEBUG: print("Form is valid. Adding Security Questions") q = QA() q.user = request.user q.question_1 = form.cleaned_data['question_1'] q.answer_1 = form.cleaned_data['answer_1'] q.question_2 = form.cleaned_data['question_2'] q.answer_2 = form.cleaned_data['answer_2'] q.question_3 = form.cleaned_data['question_3'] q.answer_3 = form.cleaned_data['answer_3'] q.question_4 = form.cleaned_data['question_4'] q.answer_4 = form.cleaned_data['answer_4'] q.question_5 = form.cleaned_data['question_5'] q.answer_5 = form.cleaned_data['answer_5'] q.save() return HttpResponseRedirect(reverse('accounts:manage_account'), RequestContext(request)) else: messages.error(request,"Did you provide Security Questions AND answers?") return render(request, 'secretqa/secretqa_add.html', {'form': form, }) else: form = QA_EditForm() return render(request, 'secretqa/secretqa_add.html', {'form': form, } )
def secretqa_add(request): # DONE: Get QA Add Working if settings.DEBUG: print("In apps.secretqa.views.secretqa_add") if request.POST: form = QA_EditForm(request.POST) if form.is_valid(): if settings.DEBUG: print("Form is valid. Adding Security Questions") q = QA() q.user = request.user q.question_1 = form.cleaned_data['question_1'] q.answer_1 = form.cleaned_data['answer_1'] q.question_2 = form.cleaned_data['question_2'] q.answer_2 = form.cleaned_data['answer_2'] q.question_3 = form.cleaned_data['question_3'] q.answer_3 = form.cleaned_data['answer_3'] q.question_4 = form.cleaned_data['question_4'] q.answer_4 = form.cleaned_data['answer_4'] q.question_5 = form.cleaned_data['question_5'] q.answer_5 = form.cleaned_data['answer_5'] q.save() return HttpResponseRedirect(reverse('accounts:manage_account'), RequestContext(request)) else: messages.error(request, "Did you provide Security Questions AND answers?") return render(request, 'secretqa/secretqa_add.html', { 'form': form, }) else: form = QA_EditForm() return render(request, 'secretqa/secretqa_add.html', { 'form': form, })
def secretqa_edit(request): # DONE: Get QA Edit working if settings.DEBUG: print(request.user) print("Entering Security Question Editing with:%s" % request.user) q = QA.objects.get(user=request.user) if settings.DEBUG: print("QA:", q) form = QA_EditForm(data=request.POST or None, instance=q) if request.POST: form = QA_EditForm(request.POST) if form.is_valid(): if settings.DEBUG: print("Form is valid - current record:", q) # Update Device here q.question_1 = form.cleaned_data['question_1'] q.answer_1 = form.cleaned_data['answer_1'] q.question_2 = form.cleaned_data['question_2'] q.answer_2 = form.cleaned_data['answer_2'] q.question_3 = form.cleaned_data['question_3'] q.answer_3 = form.cleaned_data['answer_3'] q.question_4 = form.cleaned_data['question_4'] q.answer_4 = form.cleaned_data['answer_4'] q.question_5 = form.cleaned_data['question_5'] q.answer_5 = form.cleaned_data['answer_5'] # Update Fields above if settings.DEBUG: print("Updated to:", q) q.save() return HttpResponseRedirect(reverse('accounts:manage_account'), RequestContext(request)) else: if settings.DEBUG: print("Form is invalid") messages.error(request, "There was an input problem.") return render(request, 'secretqa/secretqa_edit.html', {'form': form, 'questions': q }) else: q = QA.objects.get(user=request.user) if settings.DEBUG: print("in the get with QA:", q, ) form = QA_EditForm(initial={'question_1':q.question_1, 'answer_1':q.answer_1, 'question_2':q.question_2, 'answer_2':q.answer_2, 'question_3':q.question_3, 'answer_3':q.answer_3, 'question_4':q.question_4, 'answer_4':q.answer_4, 'question_5':q.question_5, 'answer_5':q.answer_5, }) if settings.DEBUG: print("Not in the post in the get") return render(request, 'secretqa/secretqa_edit.html', {'form': form, 'questions': q})
def secretqa_edit(request): # DONE: Get QA Edit working if settings.DEBUG: print(request.user) print("Entering Security Question Editing with:%s" % request.user) q = QA.objects.get(user=request.user) if settings.DEBUG: print("QA:", q) form = QA_EditForm(data=request.POST or None, instance=q) if request.POST: form = QA_EditForm(request.POST) if form.is_valid(): if settings.DEBUG: print("Form is valid - current record:", q) # Update Device here q.question_1 = form.cleaned_data['question_1'] q.answer_1 = form.cleaned_data['answer_1'] q.question_2 = form.cleaned_data['question_2'] q.answer_2 = form.cleaned_data['answer_2'] q.question_3 = form.cleaned_data['question_3'] q.answer_3 = form.cleaned_data['answer_3'] q.question_4 = form.cleaned_data['question_4'] q.answer_4 = form.cleaned_data['answer_4'] q.question_5 = form.cleaned_data['question_5'] q.answer_5 = form.cleaned_data['answer_5'] # Update Fields above if settings.DEBUG: print("Updated to:", q) q.save() return HttpResponseRedirect(reverse('accounts:manage_account'), RequestContext(request)) else: if settings.DEBUG: print("Form is invalid") messages.error(request, "There was an input problem.") return render(request, 'secretqa/secretqa_edit.html', { 'form': form, 'questions': q }) else: q = QA.objects.get(user=request.user) if settings.DEBUG: print( "in the get with QA:", q, ) form = QA_EditForm( initial={ 'question_1': q.question_1, 'answer_1': q.answer_1, 'question_2': q.question_2, 'answer_2': q.answer_2, 'question_3': q.question_3, 'answer_3': q.answer_3, 'question_4': q.question_4, 'answer_4': q.answer_4, 'question_5': q.question_5, 'answer_5': q.answer_5, }) if settings.DEBUG: print("Not in the post in the get") return render(request, 'secretqa/secretqa_edit.html', { 'form': form, 'questions': q })