当前位置: 首页>>代码示例>>Python>>正文


Python Log.solved方法代码示例

本文整理汇总了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])
开发者ID:anweshaiitp,项目名称:CaptureTheFlag-dep,代码行数:44,代码来源:views.py


注:本文中的models.Log.solved方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。