From da07a9a9a430e7301ff85409298e1f97fd27bee6 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Mon, 24 Apr 2023 11:56:10 -0500 Subject: [PATCH 01/11] Fix stat out-of-list --- judge/views/contests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/judge/views/contests.py b/judge/views/contests.py index d1f5245..6dd739a 100644 --- a/judge/views/contests.py +++ b/judge/views/contests.py @@ -847,6 +847,7 @@ class ContestStats(TitleMixin, ContestMixin, DetailView): continue problem_idx = codes.index(problem_code) bin_idx = math.floor(point * self.POINT_BIN / max_point) + bin_idx = max(min(bin_idx, self.POINT_BIN), 0) counter[problem_idx][bin_idx] += count for i in range(num_problems): problem_points[i] = [ From 00f2ea264840e743976d6001ba453c4200e176bf Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 26 Apr 2023 03:14:43 -0500 Subject: [PATCH 02/11] Make actionbar comment smoother --- templates/actionbar/media-js.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/actionbar/media-js.html b/templates/actionbar/media-js.html index 99ef8c5..e4f281e 100644 --- a/templates/actionbar/media-js.html +++ b/templates/actionbar/media-js.html @@ -118,8 +118,11 @@ }; $('.actionbar-comment').on('click', function() { - $('#comment-section').show(); - $('#write-comment').click(); + if ($('#comment-section').css('display') == 'none') { + $('#comment-section').show(); + } else { + $('#write-comment').click(); + } }) }); From a7c555c8537decdcba5ae9cd72cf6c2620729ee3 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 26 Apr 2023 03:38:34 -0500 Subject: [PATCH 03/11] Fix feed scroll on mobile --- judge/views/feed.py | 1 + resources/base.scss | 10 +++++++ templates/feed/feed_js.html | 54 +++++++++++++++++++++++------------- templates/feed/has_next.html | 5 +++- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/judge/views/feed.py b/judge/views/feed.py index 89bb882..cd809d5 100644 --- a/judge/views/feed.py +++ b/judge/views/feed.py @@ -27,6 +27,7 @@ class FeedView(InfinitePaginationMixin, ListView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + context["has_next_page"] = context["page_obj"].has_next() try: context["feed_content_url"] = reverse(self.url_name) except Exception as e: diff --git a/resources/base.scss b/resources/base.scss index 62e204a..48ac6af 100644 --- a/resources/base.scss +++ b/resources/base.scss @@ -853,6 +853,13 @@ select { color: #808080; } +.view-next-page { + margin-left: auto; + margin-right: auto; + margin-top: 1em; + margin-bottom: 1em; +} + @media (max-width: 799px) { #user-links, .anon { padding-right: 0.5em; @@ -877,4 +884,7 @@ select { padding: 2em; border-radius: 1em; } + .view-next-page { + display: none; + } } \ No newline at end of file diff --git a/templates/feed/feed_js.html b/templates/feed/feed_js.html index 80d878d..d5ca182 100644 --- a/templates/feed/feed_js.html +++ b/templates/feed/feed_js.html @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/templates/feed/has_next.html b/templates/feed/has_next.html index 18415b5..9cc45c9 100644 --- a/templates/feed/has_next.html +++ b/templates/feed/has_next.html @@ -1 +1,4 @@ - \ No newline at end of file + +{% if has_next_page %} + +{% endif %} \ No newline at end of file From bfedef666ed6372760b115599f4b63a19c3a4495 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 26 Apr 2023 03:41:45 -0500 Subject: [PATCH 04/11] Add trans --- locale/vi/LC_MESSAGES/django.po | 107 ++++++++++++++++---------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/locale/vi/LC_MESSAGES/django.po b/locale/vi/LC_MESSAGES/django.po index f6038f7..4a182fc 100644 --- a/locale/vi/LC_MESSAGES/django.po +++ b/locale/vi/LC_MESSAGES/django.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: lqdoj2\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-04-03 23:54+0700\n" +"POT-Creation-Date: 2023-04-26 15:39+0700\n" "PO-Revision-Date: 2021-07-20 03:44\n" "Last-Translator: Icyene\n" "Language-Team: Vietnamese\n" @@ -467,63 +467,63 @@ msgstr "" msgid "New IOI" msgstr "IOI mới" -#: judge/forms.py:105 judge/views/organization.py:514 +#: judge/forms.py:107 judge/views/organization.py:514 #: judge/views/register.py:62 #, python-brace-format msgid "You may not be part of more than {count} public groups." msgstr "Bạn không thể tham gia nhiều hơn {count} nhóm công khai." -#: judge/forms.py:147 +#: judge/forms.py:149 msgid "Any judge" msgstr "" -#: judge/forms.py:346 +#: judge/forms.py:355 msgid "Enter usernames separating by space" msgstr "Nhập các tên đăng nhập, cách nhau bởi dấu cách" -#: judge/forms.py:347 judge/views/stats.py:166 templates/stats/site.html:27 +#: judge/forms.py:356 judge/views/stats.py:166 templates/stats/site.html:27 msgid "New users" msgstr "Thành viên mới" -#: judge/forms.py:364 +#: judge/forms.py:373 #, python-brace-format msgid "These usernames don't exist: {usernames}" msgstr "Các tên đăng nhập này không tồn tại: {usernames}" -#: judge/forms.py:423 judge/views/register.py:30 +#: judge/forms.py:432 judge/views/register.py:30 #: templates/registration/registration_form.html:34 #: templates/user/base-users-table.html:5 #: templates/user/import/table_csv.html:4 msgid "Username" msgstr "Tên đăng nhập" -#: judge/forms.py:424 templates/registration/registration_form.html:46 +#: judge/forms.py:433 templates/registration/registration_form.html:46 #: templates/registration/registration_form.html:60 #: templates/user/import/table_csv.html:5 msgid "Password" msgstr "Mật khẩu" -#: judge/forms.py:450 +#: judge/forms.py:459 msgid "Two Factor Authentication tokens must be 6 decimal digits." msgstr "Two Factor Authentication phải chứa 6 chữ số." -#: judge/forms.py:463 templates/registration/totp_auth.html:32 +#: judge/forms.py:472 templates/registration/totp_auth.html:32 msgid "Invalid Two Factor Authentication token." msgstr "Token Two Factor Authentication không hợp lệ." -#: judge/forms.py:470 judge/models/problem.py:133 +#: judge/forms.py:479 judge/models/problem.py:133 msgid "Problem code must be ^[a-z0-9]+$" msgstr "Mã bài phải có dạng ^[a-z0-9]+$" -#: judge/forms.py:477 +#: judge/forms.py:486 msgid "Problem with code already exists." msgstr "Mã bài đã tồn tại." -#: judge/forms.py:484 judge/models/contest.py:91 +#: judge/forms.py:493 judge/models/contest.py:91 msgid "Contest id must be ^[a-z0-9]+$" msgstr "Mã kỳ thi phải có dạng ^[a-z0-9]+$" -#: judge/forms.py:490 +#: judge/forms.py:499 msgid "Contest with key already exists." msgstr "Mã kỳ thi đã tồn tại." @@ -533,6 +533,7 @@ msgid "N j, Y, g:i a" msgstr "g:i a j b, Y" #: judge/jinja2/datetime.py:26 templates/chat/message.html:13 +#: templates/comments/list.html:76 #, python-brace-format msgid "{time}" msgstr "{time}" @@ -2659,24 +2660,24 @@ msgstr "Báo cáo" msgid "Comment feed" msgstr "Bình luận" -#: judge/views/comment.py:40 judge/views/pagevote.py:31 +#: judge/views/comment.py:42 judge/views/pagevote.py:31 msgid "Messing around, are we?" msgstr "Messing around, are we?" -#: judge/views/comment.py:56 judge/views/pagevote.py:47 +#: judge/views/comment.py:58 judge/views/pagevote.py:47 msgid "You must solve at least one problem before you can vote." msgstr "Bạn phải giải ít nhất 1 bài trước khi được vote." -#: judge/views/comment.py:87 +#: judge/views/comment.py:89 msgid "You already voted." msgstr "Bạn đã vote." -#: judge/views/comment.py:158 judge/views/organization.py:811 +#: judge/views/comment.py:165 judge/views/organization.py:811 #: judge/views/organization.py:957 judge/views/organization.py:1122 msgid "Edited from site" msgstr "Chỉnh sửa từ web" -#: judge/views/comment.py:179 +#: judge/views/comment.py:186 msgid "Editing comment" msgstr "Chỉnh sửa bình luận" @@ -2765,53 +2766,53 @@ msgstr "F Y" msgid "%s Statistics" msgstr "%s Thống kê" -#: judge/views/contests.py:1084 +#: judge/views/contests.py:1085 #, python-format msgid "%s Rankings" msgstr "%s Bảng điểm" -#: judge/views/contests.py:1095 +#: judge/views/contests.py:1096 msgid "???" msgstr "???" -#: judge/views/contests.py:1122 +#: judge/views/contests.py:1123 #, python-format msgid "Your participation in %s" msgstr "Lần tham gia trong %s" -#: judge/views/contests.py:1123 +#: judge/views/contests.py:1124 #, python-format msgid "%s's participation in %s" msgstr "Lần tham gia của %s trong %s" -#: judge/views/contests.py:1137 +#: judge/views/contests.py:1138 msgid "Live" msgstr "Trực tiếp" -#: judge/views/contests.py:1156 templates/contest/contest-tabs.html:19 +#: judge/views/contests.py:1157 templates/contest/contest-tabs.html:19 msgid "Participation" msgstr "Lần tham gia" -#: judge/views/contests.py:1205 +#: judge/views/contests.py:1206 #, python-format msgid "%s MOSS Results" msgstr "%s Kết quả MOSS" -#: judge/views/contests.py:1241 +#: judge/views/contests.py:1242 #, python-format msgid "Running MOSS for %s..." msgstr "Đang chạy MOSS cho %s..." -#: judge/views/contests.py:1264 +#: judge/views/contests.py:1265 #, python-format msgid "Contest tag: %s" msgstr "Nhãn kỳ thi: %s" -#: judge/views/contests.py:1279 judge/views/ticket.py:72 +#: judge/views/contests.py:1280 judge/views/ticket.py:72 msgid "Issue description" msgstr "Mô tả vấn đề" -#: judge/views/contests.py:1322 +#: judge/views/contests.py:1323 #, python-format msgid "New clarification for %s" msgstr "Thông báo mới cho %s" @@ -3871,11 +3872,6 @@ msgstr "Đăng!" msgid "Please login to vote" msgstr "Đăng nhập để vote" -#: templates/comments/list.html:76 -#, python-brace-format -msgid "commented on {time}" -msgstr "bình luận vào {time}" - #: templates/comments/list.html:85 #, python-format msgid "edit %(edits)s" @@ -4099,7 +4095,7 @@ msgstr "Nhân bản" msgid "Leave contest" msgstr "Rời kỳ thi" -#: templates/contest/contest.html:42 templates/contest/list.html:399 +#: templates/contest/contest.html:42 templates/contest/list.html:401 msgid "Virtual join" msgstr "Tham gia ảo" @@ -4124,7 +4120,7 @@ msgid "AC Rate" msgstr "Tỷ lệ AC" #: templates/contest/contest.html:103 templates/contest/list.html:242 -#: templates/contest/list.html:291 templates/contest/list.html:376 +#: templates/contest/list.html:291 templates/contest/list.html:378 #: templates/problem/list.html:24 msgid "Users" msgstr "Người nộp" @@ -4193,7 +4189,7 @@ msgid "Active Contests" msgstr "Kỳ thi bạn đang tham gia" #: templates/contest/list.html:241 templates/contest/list.html:290 -#: templates/contest/list.html:333 templates/contest/list.html:373 +#: templates/contest/list.html:333 templates/contest/list.html:375 msgid "Contest" msgstr "Kỳ thi" @@ -4219,7 +4215,7 @@ msgstr "Kỳ thi sắp tới" msgid "There are no scheduled contests at this time." msgstr "Không có kỳ thi nào được lên lịch hiện tại." -#: templates/contest/list.html:363 +#: templates/contest/list.html:364 msgid "Past Contests" msgstr "Kỳ thi trong quá khứ" @@ -4357,9 +4353,13 @@ msgstr "Còn" msgid "Upcoming contests" msgstr "Kỳ thi sắp diễn ra" +#: templates/feed/has_next.html:3 +msgid "View more" +msgstr "Xem thêm" + #: templates/fine_uploader/script.html:4 msgid "Drop files here to upload" -msgstr "" +msgstr "Kéo file vào đây để tải lên" #: templates/fine_uploader/script.html:7 msgid "Upload file" @@ -4367,15 +4367,15 @@ msgstr "Tải file lên" #: templates/fine_uploader/script.html:23 msgid "Cancel" -msgstr "" +msgstr "Hủy" #: templates/fine_uploader/script.html:24 msgid "Retry" -msgstr "" +msgstr "Thử lại" #: templates/fine_uploader/script.html:26 msgid "Pause" -msgstr "" +msgstr "Dừng" #: templates/fine_uploader/script.html:27 msgid "Continue" @@ -4383,13 +4383,11 @@ msgstr "Tiếp tục" #: templates/internal/left-sidebar.html:3 msgid "Average speed" -msgstr "" +msgstr "Tốc độ trung bình" #: templates/internal/left-sidebar.html:4 -#, fuzzy -#| msgid "View requests" msgid "Slow requests" -msgstr "Đơn đăng ký" +msgstr "Requests chậm" #: templates/internal/problem.html:36 msgid "Code" @@ -5030,11 +5028,11 @@ msgstr "Lọc" msgid "Random" msgstr "Ngẫu nhiên" -#: templates/problem/submit.html:124 +#: templates/problem/submit.html:123 msgid "Your source code must contain at most 65536 characters." msgstr "Code phải chứa không quá 65536 ký tự." -#: templates/problem/submit.html:185 +#: templates/problem/submit.html:170 #, python-format msgid "" "Warning! Your default language, %(default_language)s, is " @@ -5043,7 +5041,7 @@ msgstr "" "Cẩn thận! Ngôn ngữ ưa thích của bạn, %(default_language)s, " "không được sử dụng trong bài này." -#: templates/problem/submit.html:196 +#: templates/problem/submit.html:181 #, fuzzy, python-format #| msgid "" #| "\n" @@ -5066,15 +5064,15 @@ msgstr[0] "" " Bạn còn %(left)s lần nộp\n" " " -#: templates/problem/submit.html:205 +#: templates/problem/submit.html:190 msgid "You have 0 submissions left" msgstr "Bạn đã hết lần nộp" -#: templates/problem/submit.html:239 +#: templates/problem/submit.html:224 msgid "No judge is available for this problem." msgstr "Không có máy chấm có thể chấm bài này." -#: templates/problem/submit.html:245 +#: templates/problem/submit.html:230 msgid "Submit!" msgstr "Nộp bài!" @@ -5866,6 +5864,9 @@ msgstr "Thông tin" msgid "Check all" msgstr "Chọn tất cả" +#~ msgid "commented on {time}" +#~ msgstr "bình luận vào {time}" + #~ msgid "Associated page" #~ msgstr "Trang liên kết" From 998182f65ec8abd3fdda6e1bbfb77dd69f30d189 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 26 Apr 2023 03:50:47 -0500 Subject: [PATCH 05/11] Fix bug --- judge/views/organization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/judge/views/organization.py b/judge/views/organization.py index 00f196b..e615f3d 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -304,7 +304,7 @@ class OrganizationHome(OrganizationHomeView, FeedView): return context -class OrganizationUsers(QueryStringSortMixin, OrganizationMixin, FeedView): +class OrganizationUsers(QueryStringSortMixin, OrganizationMixin, ListView): template_name = "organization/users.html" all_sorts = frozenset(("points", "problem_count", "rating", "performance_points")) default_desc = all_sorts From d4db6bc0bede7c0f1fe094a0fe460878df592a50 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 26 Apr 2023 04:02:26 -0500 Subject: [PATCH 06/11] Add pagination to org users --- judge/views/organization.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/judge/views/organization.py b/judge/views/organization.py index e615f3d..05524b8 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -304,15 +304,18 @@ class OrganizationHome(OrganizationHomeView, FeedView): return context -class OrganizationUsers(QueryStringSortMixin, OrganizationMixin, ListView): +class OrganizationUsers( + DiggPaginatorMixin, QueryStringSortMixin, OrganizationMixin, ListView +): template_name = "organization/users.html" all_sorts = frozenset(("points", "problem_count", "rating", "performance_points")) default_desc = all_sorts default_sort = "-performance_points" + paginate_by = 100 context_object_name = "users" def get_queryset(self): - return ranker( + return ( self.organization.members.filter(is_unlisted=False) .order_by(self.order, "id") .select_related("user") @@ -347,6 +350,9 @@ class OrganizationUsers(QueryStringSortMixin, OrganizationMixin, ListView): "organization_user_kick", args=[self.organization.id, self.organization.slug], ) + context["users"] = ranker( + context["users"], rank=self.paginate_by * (context["page_obj"].number - 1) + ) context["first_page_href"] = "." context["page_type"] = "users" From 7565d6ff0105a8f55a6f92332c5fe3ade2cbd081 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Fri, 28 Apr 2023 11:42:03 -0500 Subject: [PATCH 07/11] Fix edit button in editorial page --- judge/views/problem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/judge/views/problem.py b/judge/views/problem.py index cd461ea..3022f8f 100644 --- a/judge/views/problem.py +++ b/judge/views/problem.py @@ -194,7 +194,7 @@ class ProblemSolution( PageVoteDetailView, BookMarkDetailView, ): - context_object_name = "problem" + context_object_name = "solution" template_name = "problem/editorial.html" def get_title(self): @@ -220,7 +220,7 @@ class ProblemSolution( ) and not self.request.user.has_perm("judge.see_private_solution"): raise Http404() - context["solution"] = solution + context["problem"] = self.problem context["has_solved_problem"] = self.problem.id in self.get_completed_problems() return context From 30fb38f52ed5121dbd3f94de077f793afb9a82a8 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Fri, 28 Apr 2023 20:53:54 -0500 Subject: [PATCH 08/11] Show error in output instead of exception --- judge/utils/problem_data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/judge/utils/problem_data.py b/judge/utils/problem_data.py index 782e4af..8be05ae 100644 --- a/judge/utils/problem_data.py +++ b/judge/utils/problem_data.py @@ -335,7 +335,9 @@ def get_problem_case(problem, files): if next_char: s += next_char else: - raise Exception("File %s is not able to decode in utf-8" % file) + s = f"File {file} is not able to decode in utf-8" + s = s.encode("utf-8") + break qs = get_visible_content(s) cache.set(cache_key, qs, 86400) result[file] = qs From 167fa1ad6686eda9c033965b8b2746ff170bdefa Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sat, 6 May 2023 23:12:09 -0500 Subject: [PATCH 09/11] Remove unused cache --- judge/bridge/judge_handler.py | 7 ------- judge/views/problem.py | 1 - 2 files changed, 8 deletions(-) diff --git a/judge/bridge/judge_handler.py b/judge/bridge/judge_handler.py index e36c9f8..1efd45a 100644 --- a/judge/bridge/judge_handler.py +++ b/judge/bridge/judge_handler.py @@ -570,13 +570,6 @@ class JudgeHandler(ZlibPacketHandler): event.post("contest_%d" % participation.contest_id, {"type": "update"}) self._post_update_submission(submission.id, "grading-end", done=True) - # Clean up submission source file (if any) - # source_file = cache.get(f"submission_source_file:{submission.id}") - # if source_file: - # filepath = os.path.join(settings.DMOJ_SUBMISSION_ROOT, source_file) - # if os.path.exists(filepath): - # os.remove(filepath) - def on_compile_error(self, packet): logger.info( "%s: Submission failed to compile: %s", self.name, packet["submission-id"] diff --git a/judge/views/problem.py b/judge/views/problem.py index 3022f8f..7fec6fb 100644 --- a/judge/views/problem.py +++ b/judge/views/problem.py @@ -1118,7 +1118,6 @@ def problem_submit(request, problem, submission=None): # Save a query model.source = source - cache.set(f"submission_source_file:{model.id}", form.source_file_name, 3600) model.judge(rejudge=False, judge_id=form.cleaned_data["judge"]) return HttpResponseRedirect( From ad974530d5d88682c9e89c587cdbdefacf451e6d Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sun, 7 May 2023 21:37:22 -0500 Subject: [PATCH 10/11] Fix contest submission bug when modifying from admin page --- judge/admin/submission.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/judge/admin/submission.py b/judge/admin/submission.py index f621783..2a6067a 100644 --- a/judge/admin/submission.py +++ b/judge/admin/submission.py @@ -206,6 +206,11 @@ class SubmissionAdmin(admin.ModelAdmin): "problem__code", ) + def save_model(self, request, obj, form, change): + super().save_model(request, obj, form, change) + if "case_points" in form.changed_data or "case_total" in form.changed_data: + obj.update_contest() + def judge(self, request, queryset): if not request.user.has_perm( "judge.rejudge_submission" From 966e8c9db5a3cfc5c8aa49d47d9805a23cdf295e Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Mon, 15 May 2023 00:01:53 -0500 Subject: [PATCH 11/11] Fix subdomain download files --- judge/middleware.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/judge/middleware.py b/judge/middleware.py index 1c7f18a..c08b2b9 100644 --- a/judge/middleware.py +++ b/judge/middleware.py @@ -17,6 +17,7 @@ from judge.utils.views import generic_message USED_DOMAINS = ["www"] +URL_NAMES_BYPASS_SUBDOMAIN = ["submission_source_file"] class ShortCircuitMiddleware: @@ -117,7 +118,10 @@ class SubdomainMiddleware(object): subdomain = subdomain[:-1] - if subdomain in USED_DOMAINS: + if ( + subdomain in USED_DOMAINS + or resolve(request.path).url_name in URL_NAMES_BYPASS_SUBDOMAIN + ): return self.get_response(request) try: