From c9732508142c7728d97099417456273f408c716b Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Tue, 19 Oct 2021 17:41:53 -0500 Subject: [PATCH] Add clarification to problem list page --- judge/views/blog.py | 8 ++------ judge/views/contests.py | 15 +-------------- judge/views/problem.py | 13 +++++++++++-- resources/common.js | 12 +++++++----- templates/problem/list.html | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 27 deletions(-) diff --git a/judge/views/blog.py b/judge/views/blog.py index 07912b2..c16aa6e 100644 --- a/judge/views/blog.py +++ b/judge/views/blog.py @@ -57,7 +57,8 @@ class PostList(ListView): clarifications = ProblemClarification.objects.filter(problem__in=participation.contest.problems.all()) context['has_clarifications'] = clarifications.count() > 0 context['clarifications'] = clarifications.order_by('-date') - + if participation.contest.is_editable_by(self.request.user): + context['can_edit_contest'] = True context['user_count'] = lazy(Profile.objects.count, int, int) context['problem_count'] = lazy(Problem.objects.filter(is_public=True).count, int, int) context['submission_count'] = lazy(Submission.objects.count, int, int) @@ -105,11 +106,6 @@ class PostList(ListView): else: context['open_tickets'] = [] - if self.request.in_contest: - if 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(): - context['can_edit_contest'] = True return context diff --git a/judge/views/contests.py b/judge/views/contests.py index 843fe04..eb6f901 100644 --- a/judge/views/contests.py +++ b/judge/views/contests.py @@ -919,22 +919,9 @@ class NewContestClarificationView(ContestMixin, TitleMixin, SingleObjectFormView class ContestClarificationAjax(ContestMixin, DetailView): - template_name = 'contest/clarification-ajax.html'\ - - def is_accessible(self): - if not self.request.user.is_authenticated: - return False - if not self.request.in_contest: - return False - if not self.request.participation.contest == self.object: - return False - return 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): self.object = self.get_object() - if not self.is_accessible(): + if not self.object.is_accessible_by(request.user): raise Http404() polling_time = 1 # minute diff --git a/judge/views/problem.py b/judge/views/problem.py index d039252..59923d7 100644 --- a/judge/views/problem.py +++ b/judge/views/problem.py @@ -27,8 +27,8 @@ from django.views.generic.detail import SingleObjectMixin from judge.comments import CommentedDetailView from judge.forms import ProblemCloneForm, ProblemSubmitForm -from judge.models import ContestProblem, ContestSubmission, Judge, Language, Problem, ProblemGroup, \ - ProblemTranslation, ProblemType, RuntimeVersion, Solution, Submission, SubmissionSource, \ +from judge.models import ContestProblem, ContestSubmission, Judge, Language, Problem, ProblemClarification, \ + ProblemGroup, ProblemTranslation, ProblemType, RuntimeVersion, Solution, Submission, SubmissionSource, \ TranslatedProblemForeignKeyQuerySet, Organization from judge.pdf_problems import DefaultPdfMaker, HAS_PDF from judge.utils.diggpaginator import DiggPaginator @@ -439,6 +439,15 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView context['point_start'], context['point_end'], context['point_values'] = 0, 0, {} context['hide_contest_scoreboard'] = self.contest.scoreboard_visibility in \ (self.contest.SCOREBOARD_AFTER_CONTEST, self.contest.SCOREBOARD_AFTER_PARTICIPATION) + context['has_clarifications'] = False + if self.request.user.is_authenticated: + participation = self.request.profile.current_contest + if participation: + clarifications = ProblemClarification.objects.filter(problem__in=participation.contest.problems.all()) + context['has_clarifications'] = clarifications.count() > 0 + context['clarifications'] = clarifications.order_by('-date') + if participation.contest.is_editable_by(self.request.user): + context['can_edit_contest'] = True return context def get_noui_slider_points(self): diff --git a/resources/common.js b/resources/common.js index 609a654..2455f75 100644 --- a/resources/common.js +++ b/resources/common.js @@ -335,17 +335,19 @@ window.register_contest_notification = function(url) { console.log("Fail to update clarification"); }) .done(function(data) { + try { + JSON.parse(data); + } + catch (e) { + return; + } + for (i of data) { window.notify_clarification(i); } if (data.status == 403) { console.log("Fail to retrieve data"); } - else { - $('#chat-online-content').html(data).find('.toggle').each(function () { - register_toggle($(this)); - });; - } }) } get_clarifications(); diff --git a/templates/problem/list.html b/templates/problem/list.html index a79b94b..3a2df3e 100644 --- a/templates/problem/list.html +++ b/templates/problem/list.html @@ -335,6 +335,41 @@ {% endfor %} + {% if request.in_contest and request.participation.contest.use_clarifications %} +

+ {% if can_edit_contest %} +
+ {{_('Add clarifications')}} +
+ {% endif %} + {% if has_clarifications %} +
+ {{_('Clarifications')}}
+ + + + + + + {% for clarification in clarifications %} + + + + + + {% endfor %} +
{{_('Problem')}}{{_('Time')}}{{_('Description')}}
+ + {{ clarification.problem.name }} + + {{ relative_time(clarification.date) }}

{{clarification.description}}

+ {% else %} +

+ {{ _('No clarifications have been made at this time.') }} +

+ {% endif %} + {% endif %} {% if page_obj.num_pages > 1 %}
{% include "list-pages.html" %}
{% endif %}