mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-01 18:11:50 +00:00
为管理员增加强制显示最新排名的参数,用于比赛封榜后管理员查看最新排名。
This commit is contained in:
parent
b1d191eda9
commit
2e6a65d071
@ -434,30 +434,41 @@ def contest_list_page(request, page=1):
|
||||
"keyword": keyword, "join": join})
|
||||
|
||||
|
||||
def _get_rank(contest_id):
|
||||
rank = ContestRank.objects.filter(contest_id=contest_id). \
|
||||
select_related("user"). \
|
||||
order_by("-total_ac_number", "total_time"). \
|
||||
values("id", "user__id", "user__username", "user__real_name", "user__userprofile__student_id",
|
||||
"contest_id", "submission_info", "total_submission_number", "total_ac_number", "total_time")
|
||||
return rank
|
||||
|
||||
|
||||
@check_user_contest_permission
|
||||
def contest_rank_page(request, contest_id):
|
||||
contest = Contest.objects.get(id=contest_id)
|
||||
contest_problems = ContestProblem.objects.filter(contest=contest, visible=True).order_by("sort_index")
|
||||
|
||||
r = get_cache_redis()
|
||||
cache_key = str(contest_id) + "_rank_cache"
|
||||
rank = r.get(cache_key)
|
||||
|
||||
if not rank:
|
||||
rank = ContestRank.objects.filter(contest_id=contest_id). \
|
||||
select_related("user"). \
|
||||
order_by("-total_ac_number", "total_time"). \
|
||||
values("id", "user__id", "user__username", "user__real_name", "contest_id", "submission_info",
|
||||
"total_submission_number", "total_ac_number", "total_time")
|
||||
r.set(cache_key, json.dumps([dict(item) for item in rank]))
|
||||
force_real_time_rank = False
|
||||
if request.GET.get("force_real_time_rank") == "true" and (request.user.admin_type == SUPER_ADMIN or request.user == contest.created_by):
|
||||
rank = _get_rank(contest_id)
|
||||
force_real_time_rank = True
|
||||
else:
|
||||
rank = json.loads(rank)
|
||||
r = get_cache_redis()
|
||||
cache_key = str(contest_id) + "_rank_cache"
|
||||
rank = r.get(cache_key)
|
||||
|
||||
if not rank:
|
||||
rank = _get_rank(contest_id)
|
||||
r.set(cache_key, json.dumps([dict(item) for item in rank]))
|
||||
else:
|
||||
rank = json.loads(rank)
|
||||
|
||||
return render(request, "oj/contest/contest_rank.html",
|
||||
{"rank": rank, "contest": contest,
|
||||
"contest_problems": contest_problems,
|
||||
"auto_refresh": request.GET.get("auto_refresh", None) == "true",
|
||||
"show_real_name": request.GET.get("show_real_name", None) == "true", })
|
||||
"show_real_name": request.GET.get("show_real_name", None) == "true",
|
||||
"force_real_time_rank": force_real_time_rank})
|
||||
|
||||
|
||||
class ContestTimeAPIView(APIView):
|
||||
|
@ -23,13 +23,12 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12 table-responsive">
|
||||
<h2 class="text-center">排名(
|
||||
{% if contest.real_time_rank %}
|
||||
实时
|
||||
{% else %}
|
||||
已封榜
|
||||
{% endif %})
|
||||
<h2 class="text-center">排名({% if contest.real_time_rank %}实时{% else %}已封榜{% endif %})
|
||||
</h2>
|
||||
{% if force_real_time_rank %}
|
||||
<div class="alert alert-warning" role="alert">当前您使用了force_real_time_rank=true参数, 将强制显示实时结果。
|
||||
此提示仅管理员可见。</div>
|
||||
{% endif %}
|
||||
{% if rank %}
|
||||
<table class="table table-bordered table-condensed text-center">
|
||||
<thead>
|
||||
|
Loading…
Reference in New Issue
Block a user