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


Python shortcuts.error_page函数代码示例

本文整理汇总了Python中utils.shortcuts.error_page函数的典型用法代码示例。如果您正苦于以下问题:Python error_page函数的具体用法?Python error_page怎么用?Python error_page使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了error_page函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: my_submission

def my_submission(request, submission_id):
    """
    单个题目的提交详情页
    """
    try:
        result = _get_submission(submission_id, request.user)
        submission = result["submission"]
    except Submission.DoesNotExist:
        return error_page(request, u"提交不存在")

    if submission.contest_id:
        try:
            problem = ContestProblem.objects.get(id=submission.problem_id,
                                                 visible=True)
        except ContestProblem.DoesNotExist:
            return error_page(request, u"提交不存在")
    else:
        try:
            problem = Problem.objects.get(id=submission.problem_id, visible=True)
        except Problem.DoesNotExist:
            return error_page(request, u"提交不存在")

    if submission.info:
        try:
            info = json.loads(submission.info)
        except Exception:
            info = submission.info
    else:
        info = None
    user = User.objects.get(id=submission.user_id)
    return render(request, "oj/problem/my_submission.html",
                  {"submission": submission, "problem": problem, "info": info,
                   "user": user, "can_share": result["can_share"]})
开发者ID:Timeship,项目名称:OnlineJudge-QDU,代码行数:33,代码来源:views.py

示例2: _check_user_announcement_permission

    def _check_user_announcement_permission(*args, **kwargs):
        """
        这个函数检测当前用户能否查看这个公告
        """
        # CBV 的情况,第一个参数是self,第二个参数是request
        if len(args) == 2:
            request = args[-1]
        else:
            request = args[0]

        if "announcement_id" not in kwargs:
            return error_page(request, u"参数错误")
        announcement_id = kwargs["announcement_id"]

        try:
            announcement = Announcement.objects.get(id=announcement_id, visible=True)
        except Announcement.DoesNotExist:
            return error_page(request, u"公告不存在")

        # 如果公告是只有部分小组可见的
        if not announcement.is_global:
            # 用户必须是登录状态的
            if not request.user.is_authenticated():
                return HttpResponseRedirect("/login/")
            if not announcement.groups.filter(id__in=request.user.group_set.all()).exists():
                return error_page(request, u"公告不存在")
        return func(*args, **kwargs)
开发者ID:hujingguang,项目名称:OnlineJudge,代码行数:27,代码来源:decorators.py

示例3: my_submission

def my_submission(request, submission_id):
    """
    单个题目的提交详情页
    """
    try:
        result = _get_submission(submission_id, request.user)
        submission = result["submission"]
    except Submission.DoesNotExist:
        return error_page(request, u"提交不存在")

    try:
        if submission.contest_id:
            problem = ContestProblem.objects.get(id=submission.problem_id, visible=True)
        else:
            problem = Problem.objects.get(id=submission.problem_id, visible=True)
    except Exception:
        return error_page(request, u"提交不存在")

    if submission.result in [judge_result["compile_error"], judge_result["system_error"], judge_result["waiting"]]:
        info = submission.info
    else:
        info = json.loads(submission.info)
        if "test_case" in info[0]:
            info = sorted(info, key=lambda x: x["test_case"])

    user = User.objects.get(id=submission.user_id)
    return render(request, "oj/submission/my_submission.html",
                  {"submission": submission, "problem": problem, "info": info,
                   "user": user, "can_share": result["can_share"], "website_base_url": settings.WEBSITE_INFO["url"]})
开发者ID:mcmdhr,项目名称:CSOJ,代码行数:29,代码来源:views.py

示例4: problem_list_page

def problem_list_page(request, page=1):
    """
    前台的问题列表
    """
    # 正常情况
    problems = Problem.objects.filter(visible=True)

    # 搜索的情况
    keyword = request.GET.get("keyword", "").strip()
    if keyword:
        problems = problems.filter(Q(title__contains=keyword) | Q(description__contains=keyword))

    difficulty_order = request.GET.get("order_by", None)
    if difficulty_order:
        if difficulty_order[0] == "-":
            problems = problems.order_by("-difficulty")
            difficulty_order = "difficulty"
        else:
            problems = problems.order_by("difficulty")
            difficulty_order = "-difficulty"
    else:
        difficulty_order = "difficulty"

    # 按照标签筛选
    tag_text = request.GET.get("tag", None)
    if tag_text:
        try:
            tag = ProblemTag.objects.get(name=tag_text)
        except ProblemTag.DoesNotExist:
            return error_page(request, u"标签不存在")
        problems = tag.problem_set.all().filter(visible=True)

    paginator = Paginator(problems, 40)
    try:
        current_page = paginator.page(int(page))
    except Exception:
        return error_page(request, u"不存在的页码")

    previous_page = next_page = None

    try:
        previous_page = current_page.previous_page_number()
    except Exception:
        pass

    try:
        next_page = current_page.next_page_number()
    except Exception:
        pass

    # 右侧标签列表 按照关联的题目的数量排序 排除题目数量为0的
    tags = ProblemTag.objects.annotate(problem_number=Count("problem")).filter(problem_number__gt=0).order_by(
        "-problem_number")

    return render(request, "oj/problem/problem_list.html",
                  {"problems": current_page, "page": int(page),
                   "previous_page": previous_page, "next_page": next_page,
                   "keyword": keyword, "tag": tag_text,
                   "tags": tags, "difficulty_order": difficulty_order})
开发者ID:8cbx,项目名称:OnlineJudge,代码行数:59,代码来源:views.py

示例5: reset_password_page

def reset_password_page(request, token):
    try:
        user = User.objects.get(reset_password_token=token)
    except User.DoesNotExist:
        return error_page(request, u"链接已失效")
    if (now() - user.reset_password_token_create_time).total_seconds() > 30 * 60:
        return error_page(request, u"链接已过期")
    return render(request, "oj/account/reset_password.html", {"user": user})
开发者ID:ArchFeh,项目名称:OnlineJudge,代码行数:8,代码来源:views.py

示例6: contest_problem_submissions_list_page

def contest_problem_submissions_list_page(request, contest_id, page=1):
    """
    单个比赛中的所有提交(包含自己和别人,自己可查提交结果,其他人不可查)
    """
    try:
        contest = Contest.objects.get(id=contest_id)
    except Contest.DoesNotExist:
        return error_page(request, u"比赛不存在")
    # 以下是本场比赛中所有的提交
    submissions = Submission.objects.filter(contest_id=contest_id). \
        values("id", "contest_id", "problem_id", "result", "create_time", "accepted_answer_time", "language", "user_id").order_by("-create_time")
    language = request.GET.get("language", None)
    filter = None
    if language:
        submissions = submissions.filter(language=int(language))
        filter = {"name": "language", "content": language}
    result = request.GET.get("result", None)
    if result:
        submissions = submissions.filter(result=int(result))
        filter = {"name": "result", "content": result}
    paginator = Paginator(submissions, 20)

    # 为查询题目标题创建新字典
    title = {}
    contest_problems = ContestProblem.objects.filter(contest=contest)
    for item in contest_problems:
        title[item.id] = item.title
    for item in submissions:
        item['title'] = title[item['problem_id']]

    try:
        current_page = paginator.page(int(page))
    except Exception:
        return error_page(request, u"不存在的页码")
    previous_page = next_page = None
    try:
        previous_page = current_page.previous_page_number()
    except Exception:
        pass
    try:
        next_page = current_page.next_page_number()
    except Exception:
        pass

    for item in current_page:
        # 自己提交的 管理员和创建比赛的可以看到所有的提交链接
        if item["user_id"] == request.user.id or request.user.admin_type == SUPER_ADMIN or \
                        request.user == contest.created_by:
            item["show_link"] = True
        else:
            item["show_link"] = False

    return render(request, "oj/contest/submissions_list.html",
                  {"submissions": current_page, "page": int(page),
                   "previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20,
                   "contest": contest, "filter":filter})
开发者ID:pathminer,项目名称:OnlineJudge,代码行数:56,代码来源:views.py

示例7: group_list_page

def group_list_page(request, page=1):
    groups = Group.objects.filter(visible=True, join_group_setting__lte=2)
    # 搜索的情况
    keyword = request.GET.get("keyword", None)
    if keyword:
        groups = groups.filter(Q(name__contains=keyword) | Q(description__contains=keyword))

    paginator = Paginator(groups, 20)
    try:
        current_page = paginator.page(int(page))
    except Exception:
        return error_page(request, u"不存在的页码")

    previous_page = next_page = None

    try:
        previous_page = current_page.previous_page_number()
    except Exception:
        pass
    try:
        next_page = current_page.next_page_number()
    except Exception:
        pass

    return render(request, "oj/group/group_list.html", {
        "groups": current_page.object_list,
        "contests": current_page, "page": int(page),
        "previous_page": previous_page, "next_page": next_page,
        "keyword": keyword
    })
开发者ID:isheng5,项目名称:OnlineJudge,代码行数:30,代码来源:views.py

示例8: contest_problem_page

def contest_problem_page(request, contest_id, contest_problem_id):
    """
    单个比赛题目的详情页
    """
    contest = Contest.objects.get(id=contest_id)
    try:
        contest_problem = ContestProblem.objects.get(id=contest_problem_id, visible=True)
    except ContestProblem.DoesNotExist:
        return error_page(request, u"比赛题目不存在")
    warning = u"您已经提交过本题的正确答案,重复提交可能造成时间累计。"
    show_warning = False
    try:
        submission = ContestSubmission.objects.get(user=request.user, contest=contest, problem=contest_problem)
        show_warning = submission.ac
    except ContestSubmission.DoesNotExist:
        pass

    # 已经结束
    if contest.status == CONTEST_ENDED:
        show_warning = True
        warning = u"比赛已经结束"
    elif contest.status == CONTEST_NOT_START:
        show_warning = True
        warning = u"比赛没有开始,您是管理员,可以提交和测试题目,但是目前的提交不会计入排名。"

    show_submit_code_area = False
    if contest.status == CONTEST_UNDERWAY:
        show_submit_code_area = True
    if request.user.admin_type == SUPER_ADMIN or request.user == contest.created_by:
        show_submit_code_area = True

    return render(request, "oj/contest/contest_problem.html", {"contest_problem": contest_problem, "contest": contest,
                                                               "samples": json.loads(contest_problem.samples),
                                                               "show_warning": show_warning, "warning": warning,
                                                               "show_submit_code_area": show_submit_code_area})
开发者ID:eduStack,项目名称:OnlineJudge,代码行数:35,代码来源:views.py

示例9: application_page

def application_page(request, request_id):
    try:
        application = JoinGroupRequest.objects.get(user=request.user, pk=request_id)
    except JoinGroupRequest.DoesNotExist:
        return error_page(request, u"申请不存在")
    return render(request, "oj/group/my_application.html",
                  {"application": application})
开发者ID:isheng5,项目名称:OnlineJudge,代码行数:7,代码来源:views.py

示例10: check

 def check(*args, **kwargs):
     request = args[-1]
     if request.user.is_authenticated() and request.user.admin_type:
         return func(*args, **kwargs)
     if request.is_ajax():
         return error_response(u"需要管理员权限")
     else:
         return error_page(request, u"需要管理员权限,如果没有登录,请先登录")
开发者ID:uestcxl,项目名称:OnlineJudge,代码行数:8,代码来源:decorators.py

示例11: contest_problem_my_submissions_list_page

def contest_problem_my_submissions_list_page(request, contest_id, contest_problem_id):
    """
    我比赛单个题目的所有提交列表
    """
    try:
        Contest.objects.get(id=contest_id)
    except Contest.DoesNotExist:
        return error_page(request, u"比赛不存在")
    try:
        contest_problem = ContestProblem.objects.get(id=contest_problem_id, visible=True)
    except ContestProblem.DoesNotExist:
        return error_page(request, u"比赛问题不存在")
    submissions = Submission.objects.filter(user_id=request.user.id, problem_id=contest_problem.id). \
        order_by("-create_time"). \
        values("id", "result", "create_time", "accepted_answer_time", "language")
    return render(request, "oj/submission/problem_my_submissions_list.html",
                  {"submissions": submissions, "problem": contest_problem})
开发者ID:adamwen829,项目名称:OnlineJudge,代码行数:17,代码来源:views.py

示例12: application_list_page

def application_list_page(request, group_id):
    try:
        group = Group.objects.get(id=group_id, visible=True)
    except Group.DoesNotExist:
        return error_page(request, u"小组不存在")
    applications = JoinGroupRequest.objects.filter(user=request.user, group=group)
    return render(request, "oj/group/my_application_list.html",
                  {"group": group, "applications": applications})
开发者ID:isheng5,项目名称:OnlineJudge,代码行数:8,代码来源:views.py

示例13: get

 def get(self, request):
     callback = request.GET.get("callback", None)
     if not callback or callback != settings.SSO["callback"]:
         return error_page(request, u"参数错误")
     token = rand_str()
     request.user.auth_token = token
     request.user.save()
     return render(request, "oj/account/sso.html", {"redirect_url": callback + "?token=" + token, "callback": callback})
开发者ID:adamwen829,项目名称:OnlineJudge,代码行数:8,代码来源:views.py

示例14: my_submission_list_page

def my_submission_list_page(request, page=1):
    """
    我的所有提交的列表页
    """
    # 显示所有人的提交 这是管理员的调试功能
    show_all = request.GET.get("show_all", False) == "true" and request.user.admin_type == SUPER_ADMIN
    if show_all:
        submissions = Submission.objects.filter(contest_id__isnull=True)
    else:
        submissions = Submission.objects.filter(user_id=request.user.id, contest_id__isnull=True)
    submissions = submissions.values("id", "user_id", "problem_id", "result", "create_time", "accepted_answer_time",
                                     "language").order_by("-create_time")

    language = request.GET.get("language", None)
    filter = None
    if language:
        submissions = submissions.filter(language=int(language))
        filter = {"name": "language", "content": language}
    result = request.GET.get("result", None)
    if result:
        submissions = submissions.filter(result=int(result))
        filter = {"name": "result", "content": result}

    # 因为提交页面经常会有重复的题目和用户,缓存一下查询结果
    cache_result = {"problem": {}, "user": {}}
    for item in submissions:
        problem_id = item["problem_id"]
        if problem_id not in cache_result["problem"]:
            problem = Problem.objects.get(id=problem_id)
            cache_result["problem"][problem_id] = problem.title
        item["title"] = cache_result["problem"][problem_id]

        if show_all:
            user_id = item["user_id"]
            if user_id not in cache_result["user"]:
                user = User.objects.get(id=user_id)
                cache_result["user"][user_id] = user
            item["user"] = cache_result["user"][user_id]

    paginator = Paginator(submissions, 20)
    try:
        current_page = paginator.page(int(page))
    except Exception:
        return error_page(request, u"不存在的页码")
    previous_page = next_page = None
    try:
        previous_page = current_page.previous_page_number()
    except Exception:
        pass
    try:
        next_page = current_page.next_page_number()
    except Exception:
        pass

    return render(request, "oj/submission/my_submissions_list.html",
                  {"submissions": current_page, "page": int(page),
                   "previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20,
                   "filter": filter, "show_all": show_all})
开发者ID:rayeya,项目名称:OnlineJudge,代码行数:58,代码来源:views.py

示例15: problem_page

def problem_page(request, problem_id):
    """
    前台题目详情页
    """
    try:
        problem = Problem.objects.get(id=problem_id, visible=True)
    except Problem.DoesNotExist:
        return error_page(request, u"题目不存在")
    return render(request, "oj/problem/problem.html", {"problem": problem, "samples": json.loads(problem.samples)})
开发者ID:8cbx,项目名称:OnlineJudge,代码行数:9,代码来源:views.py


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