本文整理汇总了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'))