本文整理匯總了Python中questions.forms.AnswerForm.add_error方法的典型用法代碼示例。如果您正苦於以下問題:Python AnswerForm.add_error方法的具體用法?Python AnswerForm.add_error怎麽用?Python AnswerForm.add_error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類questions.forms.AnswerForm
的用法示例。
在下文中一共展示了AnswerForm.add_error方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: QuestionsPage
# 需要導入模塊: from questions.forms import AnswerForm [as 別名]
# 或者: from questions.forms.AnswerForm import add_error [as 別名]
def QuestionsPage(request):
if request.user.registered:
if request.user.user_profile.win == True:
return redirect(reverse('win_page'))
else:
if request.method == 'GET':
try:
question = Question.objects.get(current=True)
except ObjectDoesNotExist:
request.user.user_profile.win = True
request.user.user_profile.save()
return redirect(reverse('win_page'))
answer_form = AnswerForm()
return render(request,'Questions/questionspage.html',{"question":question,"answer_form":answer_form})
elif request.method == 'POST':
question = Question.objects.get(current=True)
answer_form=AnswerForm(request.POST,request.FILES)
if answer_form.is_valid():
recieved_file = request.FILES['file']
sample_file = open(os.path.join(settings.BASE_DIR,'files/output/'+question.title+".txt"), 'rb')
flag = True
line1 = recieved_file.readline()
line2 = sample_file.readline()
while line1 != bytes('#','utf-8') or line2 != bytes('#','utf-8'):
print(line1,line2)
if line1 != line2:
flag = False
break
line1 = recieved_file.readline()
line2 = sample_file.readline()
print(flag)
sample_file.close
if flag:
request.user.user_profile.win = True
request.user.user_profile.time_counter = int(format(datetime.now(), 'U'))
request.user.user_profile.save()
return redirect(reverse('win_page'))
else:
answer_form.add_error('file',"Oops, This is not the answer we expected")
return render(request,'Questions/questionspage.html',{"question":question,"answer_form":answer_form})
else:
return render(request,'Questions/questionspage.html',{"question":question,"answer_form":answer_form})
else:
return redirect(reverse('register_page'))