Merge branch 'LQDJudge:master' into master

This commit is contained in:
Dung T.Bui 2023-05-16 12:47:53 +07:00 committed by GitHub
commit 49a186f72f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 132 additions and 90 deletions

View file

@ -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"

View file

@ -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"]

View file

@ -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:

View file

@ -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

View file

@ -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] = [

View file

@ -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:

View file

@ -304,15 +304,18 @@ class OrganizationHome(OrganizationHomeView, FeedView):
return context
class OrganizationUsers(QueryStringSortMixin, OrganizationMixin, FeedView):
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, FeedView):
"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"

View file

@ -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
@ -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(