Modify json resolver
This commit is contained in:
parent
d143218206
commit
fdb5293edb
1 changed files with 16 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.http import HttpResponseForbidden
|
from django.http import HttpResponseForbidden, JsonResponse
|
||||||
from judge.models import Contest
|
from judge.models import Contest
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class Resolver(TemplateView):
|
||||||
hidden_subtasks = self.contest.format.get_hidden_subtasks()
|
hidden_subtasks = self.contest.format.get_hidden_subtasks()
|
||||||
num_problems = len(problems)
|
num_problems = len(problems)
|
||||||
problem_sub = [0] * num_problems
|
problem_sub = [0] * num_problems
|
||||||
sub_frozen = [0] * num_problems
|
sub_frozen = [[] for _ in range(num_problems)]
|
||||||
problems_json = {str(i): {} for i in range(1, num_problems + 1)}
|
problems_json = {str(i): {} for i in range(1, num_problems + 1)}
|
||||||
|
|
||||||
users = {}
|
users = {}
|
||||||
|
@ -126,10 +126,8 @@ class Resolver(TemplateView):
|
||||||
|
|
||||||
for i in hidden_subtasks:
|
for i in hidden_subtasks:
|
||||||
order = id_to_order[i]
|
order = id_to_order[i]
|
||||||
if hidden_subtasks[i]:
|
sub_frozen[order - 1] = list(hidden_subtasks[i])
|
||||||
sub_frozen[order - 1] = min(hidden_subtasks[i])
|
|
||||||
else:
|
|
||||||
sub_frozen[order - 1] = problem_sub[order - 1] + 1
|
|
||||||
return {
|
return {
|
||||||
"problem_sub": problem_sub,
|
"problem_sub": problem_sub,
|
||||||
"sub_frozen": sub_frozen,
|
"sub_frozen": sub_frozen,
|
||||||
|
@ -143,8 +141,15 @@ class Resolver(TemplateView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if request.user.is_superuser:
|
if not request.user.is_superuser:
|
||||||
self.contest = Contest.objects.get(key=kwargs.get("contest"))
|
return HttpResponseForbidden()
|
||||||
if self.contest.format.has_hidden_subtasks:
|
self.contest = Contest.objects.get(key=kwargs.get("contest"))
|
||||||
return super(Resolver, self).get(request, *args, **kwargs)
|
if not self.contest.format.has_hidden_subtasks:
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
|
if self.request.GET.get("json"):
|
||||||
|
json_dumps_params = {"ensure_ascii": False}
|
||||||
|
return JsonResponse(
|
||||||
|
self.get_contest_json(), json_dumps_params=json_dumps_params
|
||||||
|
)
|
||||||
|
return super(Resolver, self).get(request, *args, **kwargs)
|
||||||
|
|
Loading…
Reference in a new issue