本文整理汇总了Python中models.Log.solved方法的典型用法代码示例。如果您正苦于以下问题:Python Log.solved方法的具体用法?Python Log.solved怎么用?Python Log.solved使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Log
的用法示例。
在下文中一共展示了Log.solved方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit_answer
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import solved [as 别名]
def submit_answer(request, question_id):
if request.method == "POST" and "answer" in request.POST:
try:
question = Question.objects.filter(valid=True).get(pk=question_id)
except ObjectDoesNotExist:
return HttpResponse(info_messages["invalid_question"][1])
question_status_obj = QuestionStatus.objects.filter(team_id=request.user).filter(question_id=question)
# Question Already Answered
if len(question_status_obj.filter(question_status="AW")) != 0:
return HttpResponse(info_messages["answered"][1])
_log = Log.objects.filter(team_id=request.user).filter(question_id=question)
if len(_log) == 0:
log = Log(team_id=request.user, question_id=question)
else:
log = _log[0]
log.submission_time = timezone.now()
# Question Already Opened
if len(question_status_obj) != 0:
qs = question_status_obj[0]
else:
qs = QuestionStatus(team_id=request.user, question_id=question, question_status="OP")
answer = request.POST["answer"]
if question.answer == answer:
log.solved = True
qs.question_status = "AW"
qs.submission_time = timezone.now()
qs.save()
team = TeamDetail.objects.filter(team=qs.team_id)[0]
team.points += qs.question_id.points
team.save()
log.save()
return HttpResponse(info_messages["correct answer"][1])
else:
log.count_fail += 1
qs.submission_time = timezone.now()
qs.save()
log.save()
return HttpResponse(info_messages["incorrect answer"][1])
return HttpResponse(info_messages["invalid_request"][1])