Refactor contest views

This commit is contained in:
cuom1999 2023-01-04 15:21:03 -06:00
parent d42cf64abd
commit 48adf7e6b8
3 changed files with 19 additions and 13 deletions

View file

@ -295,7 +295,12 @@ class ContestMixin(object):
context["meta_description"] = self.object.summary or metadata[0] context["meta_description"] = self.object.summary or metadata[0]
context["og_image"] = self.object.og_image or metadata[1] context["og_image"] = self.object.og_image or metadata[1]
context["has_moss_api_key"] = settings.MOSS_API_KEY is not None context["has_moss_api_key"] = settings.MOSS_API_KEY is not None
context["can_use_resolver"] = self.object.format.has_hidden_subtasks context["contest_has_hidden_subtasks"] = self.object.format.has_hidden_subtasks
context[
"show_final_ranking"
] = self.object.format.has_hidden_subtasks and self.object.is_editable_by(
self.request.user
)
context["logo_override_image"] = self.object.logo_override_image context["logo_override_image"] = self.object.logo_override_image
if ( if (
not context["logo_override_image"] not context["logo_override_image"]
@ -989,7 +994,10 @@ def contest_ranking_ajax(request, contest, participation=None):
raise Http404() raise Http404()
if show_final: if show_final:
if not request.user.is_superuser or not contest.format.has_hidden_subtasks: if (
not contest.is_editable_by(request.user)
or not contest.format.has_hidden_subtasks
):
raise Http404() raise Http404()
queryset = contest.users.filter(virtual__gte=0) queryset = contest.users.filter(virtual__gte=0)
@ -1075,9 +1083,9 @@ class ContestFinalRanking(LoginRequiredMixin, ContestRanking):
page_type = "final_ranking" page_type = "final_ranking"
def get_ranking_list(self): def get_ranking_list(self):
if not self.request.user.is_superuser: if not self.object.is_editable_by(self.request.user):
raise Http404() raise Http404()
if self.object.format_name != "ioi16": if self.object.format.has_hidden_subtasks:
raise Http404() raise Http404()
return get_contest_ranking_list(self.request, self.object, show_final=True) return get_contest_ranking_list(self.request, self.object, show_final=True)
@ -1264,11 +1272,7 @@ class NewContestClarificationView(ContestMixin, TitleMixin, SingleObjectFormView
return False return False
if not self.request.participation.contest == self.get_object(): if not self.request.participation.contest == self.get_object():
return False return False
return ( return self.get_object().is_editable_by(self.request.user)
self.request.user.is_superuser
or self.request.profile in self.request.participation.contest.authors.all()
or self.request.profile in self.request.participation.contest.curators.all()
)
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if not self.is_accessible(): if not self.is_accessible():

View file

@ -516,7 +516,7 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView):
self.selected_languages = set(request.GET.getlist("language")) self.selected_languages = set(request.GET.getlist("language"))
self.selected_statuses = set(request.GET.getlist("status")) self.selected_statuses = set(request.GET.getlist("status"))
if self.contest and self.contest.is_editable_by(self.request.user): if self.in_contest and self.contest.is_editable_by(self.request.user):
self.include_frozen = True self.include_frozen = True
if "results" in request.GET: if "results" in request.GET:

View file

@ -22,9 +22,11 @@
{{ make_tab_item('ranking', 'fa fa-bar-chart', None, _('Hidden Rankings')) }} {{ make_tab_item('ranking', 'fa fa-bar-chart', None, _('Hidden Rankings')) }}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if request.user.is_superuser and can_use_resolver %} {% if request.user.is_superuser and contest_has_hidden_subtasks %}
{{ make_tab_item('resolver', 'fa fa-check', url('resolver', contest.key), _('Resolver')) }} {{ make_tab_item('resolver', 'fa fa-check', url('resolver', contest.key), _('Resolver')) }}
{{ make_tab_item('final_ranking', 'fa fa-bar-chart', url('contest_final_ranking', contest.key), _('Final rankings')) }} {% endif %}
{% if show_final_ranking %}
{{ make_tab_item('final_ranking', 'fa fa-bar-chart', url('contest_final_ranking', contest.key), _('Final rankings')) }}
{% endif %} {% endif %}
{% if can_edit %} {% if can_edit %}
{% if perms.judge.moss_contest and has_moss_api_key %} {% if perms.judge.moss_contest and has_moss_api_key %}