From 308006f7bd5c8624dddb7d26c841359420230966 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Fri, 31 May 2024 00:35:20 -0500 Subject: [PATCH] Add virtual participation to ranking list when virtual joining --- judge/views/contests.py | 31 +++++++++++++++++-------------- judge/views/user.py | 4 +++- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/judge/views/contests.py b/judge/views/contests.py index 99ff7e7..fb17c28 100644 --- a/judge/views/contests.py +++ b/judge/views/contests.py @@ -1107,7 +1107,6 @@ def get_contest_ranking_list( contest, participation=None, ranking_list=contest_ranking_list, - show_current_virtual=False, ranker=ranker, show_final=False, ): @@ -1117,21 +1116,26 @@ def get_contest_ranking_list( .order_by("order") ) + # Set participation to current virtual join if it's None + ranking_participation = None + if participation is None and request.user.is_authenticated: + participation = request.profile.current_contest + if participation is None or participation.contest_id != contest.id: + participation = None + if participation is not None and participation.virtual: + ranking_participation = make_contest_ranking_profile( + contest, participation, problems + ) + + ranking_list_result = ranking_list(contest, problems, show_final=show_final) + + if ranking_participation and ranking_participation not in ranking_list_result: + ranking_list_result.append(ranking_participation) + users = ranker( - ranking_list(contest, problems, show_final=show_final), + ranking_list_result, key=attrgetter("points", "cumtime", "tiebreaker"), ) - - if show_current_virtual: - if participation is None and request.user.is_authenticated: - participation = request.profile.current_contest - if participation is None or participation.contest_id != contest.id: - participation = None - if participation is not None and participation.virtual: - users = chain( - [("-", make_contest_ranking_profile(contest, participation, problems))], - users, - ) return users, problems @@ -1272,7 +1276,6 @@ class ContestParticipationList(LoginRequiredMixin, ContestRankingBase): return get_contest_ranking_list( self.request, self.object, - show_current_virtual=False, ranking_list=partial(base_contest_ranking_list, queryset=queryset), ranker=lambda users, key: ( (user.participation.virtual or live_link, user) for user in users diff --git a/judge/views/user.py b/judge/views/user.py index 079abd3..6feaffa 100644 --- a/judge/views/user.py +++ b/judge/views/user.py @@ -203,7 +203,9 @@ class UserAboutPage(UserPage): "label": rating.contest.name, "rating": rating.rating, "ranking": rating.rank, - "link": reverse("contest_ranking", args=(rating.contest.key,)), + "link": reverse("contest_ranking", args=(rating.contest.key,)) + + "#!" + + self.object.username, "timestamp": (rating.contest.end_time - EPOCH).total_seconds() * 1000, "date": date_format(