Merge branch 'dev' into hohoTT-dev
Conflicts: contest/views.py
This commit is contained in:
@@ -373,7 +373,7 @@ class ContestProblemAdminAPItEST(APITestCase):
|
||||
|
||||
def test_query_contest_problem_exists_by_contest_id(self):
|
||||
self.client.login(username="test3", password="testaa")
|
||||
response = self.client.get(self.url + "?contest_id=1")
|
||||
response = self.client.get(self.url + "?contest_id="+ str(self.global_contest.id))
|
||||
self.assertEqual(response.data["code"], 0)
|
||||
self.assertEqual(len(response.data["data"]), 0)
|
||||
|
||||
|
||||
@@ -317,9 +317,22 @@ def contest_problems_list_page(request, contest_id):
|
||||
比赛所有题目的列表页
|
||||
"""
|
||||
try:
|
||||
contest_problems = ContestProblem.objects.filter(contest=Contest.objects.get(id=contest_id)).order_by("sort_index")
|
||||
except ContestProblem.DoesNotExist:
|
||||
return error_page(request, u"比赛题目不存在")
|
||||
contest = Contest.objects.get(id=contest_id)
|
||||
except Contest.DoesNotExist:
|
||||
return error_page(request, u"比赛不存在")
|
||||
contest_problems = ContestProblem.objects.filter(contest=contest).order_by("sort_index")
|
||||
submissions = ContestSubmission.objects.filter(user=request.user, contest=contest)
|
||||
state = {}
|
||||
for item in submissions:
|
||||
state[item.problem_id] = item.ac
|
||||
for item in contest_problems:
|
||||
if item.id in state:
|
||||
if state[item.id]:
|
||||
item.state = 1
|
||||
else:
|
||||
item.state = 2
|
||||
else:
|
||||
item.state = 0
|
||||
# 右侧的公告列表
|
||||
announcements = Announcement.objects.filter(is_global=True, visible=True).order_by("-create_time")
|
||||
return render(request, "oj/contest/contest_problems_list.html", {"contest_problems": contest_problems,
|
||||
@@ -342,7 +355,7 @@ def contest_list_page(request, page=1):
|
||||
# 筛选我能参加的比赛
|
||||
join = request.GET.get("join", None)
|
||||
if join:
|
||||
contests = contests.filter(Q(contest_type__in=[1, 2]) | Q(groups__in=request.user.group_set.all())).\
|
||||
contests = contests.filter(Q(contest_type__in=[1, 2]) | Q(groups__in=request.user.group_set.all())). \
|
||||
filter(end_time__gt=datetime.datetime.now(), start_time__lt=datetime.datetime.now())
|
||||
|
||||
paginator = Paginator(contests, 20)
|
||||
@@ -373,7 +386,6 @@ def contest_list_page(request, page=1):
|
||||
"join": join})
|
||||
|
||||
|
||||
|
||||
def _cmp(x, y):
|
||||
if x["total_ac"] > y["total_ac"]:
|
||||
return 1
|
||||
@@ -390,10 +402,11 @@ def _cmp(x, y):
|
||||
def contest_rank_page(request, contest_id):
|
||||
contest = Contest.objects.get(id=contest_id)
|
||||
contest_problems = ContestProblem.objects.filter(contest=contest).order_by("sort_index")
|
||||
result = ContestSubmission.objects.values("user_id").annotate(total_submit=Count("user_id"))
|
||||
result = ContestSubmission.objects.filter(contest=contest).values("user_id").annotate(
|
||||
total_submit=Sum("total_submission_number"))
|
||||
for i in range(0, len(result)):
|
||||
# 这个人所有的提交
|
||||
submissions = ContestSubmission.objects.filter(user_id=result[i]["user_id"])
|
||||
submissions = ContestSubmission.objects.filter(user_id=result[i]["user_id"], contest_id=contest_id)
|
||||
result[i]["submissions"] = {}
|
||||
for item in submissions:
|
||||
result[i]["submissions"][item.problem_id] = item
|
||||
@@ -401,11 +414,6 @@ def contest_rank_page(request, contest_id):
|
||||
result[i]["user"] = User.objects.get(id=result[i]["user_id"])
|
||||
result[i]["total_time"] = submissions.filter(ac=True).aggregate(total_time=Sum("total_time"))["total_time"]
|
||||
|
||||
|
||||
return render(request, "oj/contest/contest_rank.html",
|
||||
{"contest": contest, "contest_problems": contest_problems, "result": sorted(result, cmp=_cmp, reverse=True)})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{"contest": contest, "contest_problems": contest_problems,
|
||||
"result": sorted(result, cmp=_cmp, reverse=True)})
|
||||
|
||||
Reference in New Issue
Block a user