Move problem clarification to contest clarification

This commit is contained in:
cuom1999 2022-10-12 21:19:22 -05:00
parent f001ae4e0a
commit 0ee7de1b46
11 changed files with 115 additions and 79 deletions

View file

@ -14,7 +14,7 @@ from judge.models import (
Contest,
Language,
Problem,
ProblemClarification,
ContestProblemClarification,
Profile,
Submission,
Ticket,
@ -50,8 +50,8 @@ class FeedView(ListView):
if self.request.user.is_authenticated:
participation = self.request.profile.current_contest
if participation:
clarifications = ProblemClarification.objects.filter(
problem__in=participation.contest.problems.all()
clarifications = ContestProblemClarification.objects.filter(
problem__in=participation.contest.contest_problems.all()
)
context["has_clarifications"] = clarifications.count() > 0
context["clarifications"] = clarifications.order_by("-date")

View file

@ -65,7 +65,7 @@ from judge.models import (
Problem,
Profile,
Submission,
ProblemClarification,
ContestProblemClarification,
)
from judge.tasks import run_moss
from judge.utils.celery import redirect_to_task_status
@ -1179,7 +1179,7 @@ class ContestTagDetail(TitleMixin, ContestTagDetailAjax):
return _("Contest tag: %s") % self.object.name
class ProblemClarificationForm(forms.Form):
class ContestProblemClarificationForm(forms.Form):
body = forms.CharField(
widget=HeavyPreviewPageDownWidget(
preview=reverse_lazy("comment_preview"),
@ -1190,12 +1190,12 @@ class ProblemClarificationForm(forms.Form):
def __init__(self, request, *args, **kwargs):
self.request = request
super(ProblemClarificationForm, self).__init__(*args, **kwargs)
super(ContestProblemClarificationForm, self).__init__(*args, **kwargs)
self.fields["body"].widget.attrs.update({"placeholder": _("Issue description")})
class NewContestClarificationView(ContestMixin, TitleMixin, SingleObjectFormView):
form_class = ProblemClarificationForm
form_class = ContestProblemClarificationForm
template_name = "contest/clarification.html"
def get_form_kwargs(self):
@ -1225,12 +1225,13 @@ class NewContestClarificationView(ContestMixin, TitleMixin, SingleObjectFormView
problem_code = self.request.POST["problem"]
description = form.cleaned_data["body"]
clarification = ProblemClarification(description=description)
clarification.problem = Problem.objects.get(code=problem_code)
clarification = ContestProblemClarification(description=description)
clarification.problem = get_object_or_404(
ContestProblem, contest=self.get_object(), problem__code=problem_code
)
clarification.save()
link = reverse("home")
return HttpResponseRedirect(link)
return HttpResponseRedirect(reverse("problem_list"))
def get_title(self):
return "New clarification for %s" % self.object.name
@ -1264,26 +1265,27 @@ class ContestClarificationAjax(ContestMixin, DetailView):
minutes=polling_time
)
queryset = list(
ProblemClarification.objects.filter(
problem__in=self.object.problems.all(), date__gte=last_one_minute
).values("problem", "problem__name", "description")
queryset = ContestProblemClarification.objects.filter(
problem__in=self.object.contest_problems.all(), date__gte=last_one_minute
)
problems = list(
ContestProblem.objects.filter(contest=self.object)
.order_by("order")
.values("problem")
.values_list("problem__code", flat=True)
)
problems = [i["problem"] for i in problems]
for cla in queryset:
cla["order"] = self.object.get_label_for_problem(
problems.index(cla["problem"])
)
res = []
for clarification in queryset:
value = {
"order": self.object.get_label_for_problem(
problems.index(clarification.problem.problem.code)
),
"problem__name": clarification.problem.problem.name,
"description": clarification.description,
}
res.append(value)
return JsonResponse(
queryset, safe=False, json_dumps_params={"ensure_ascii": False}
)
return JsonResponse(res, safe=False, json_dumps_params={"ensure_ascii": False})
def update_contest_mode(request):

View file

@ -930,7 +930,12 @@ class EditOrganizationContest(
for problem_form in problem_formset.deleted_objects:
problem_form.delete()
super().post(request, *args, **kwargs)
return HttpResponseRedirect(reverse("organization_contests", args=(self.organization_id,self.organization.slug)))
return HttpResponseRedirect(
reverse(
"organization_contests",
args=(self.organization_id, self.organization.slug),
)
)
self.object = self.contest
return self.render_to_response(
@ -1062,9 +1067,9 @@ class EditOrganizationBlog(
_("Not allowed to edit this blog"),
)
def delete_blog(self , request , *args , **kwargs):
def delete_blog(self, request, *args, **kwargs):
self.blog_id = kwargs["blog_pk"]
BlogPost.objects.get(pk = self.blog_id).delete()
BlogPost.objects.get(pk=self.blog_id).delete()
def get(self, request, *args, **kwargs):
res = self.setup_blog(request, *args, **kwargs)
@ -1076,10 +1081,13 @@ class EditOrganizationBlog(
res = self.setup_blog(request, *args, **kwargs)
if res:
return res
if request.POST['action'] == 'Delete':
if request.POST["action"] == "Delete":
self.create_notification("Delete blog")
self.delete_blog(request , *args , **kwargs)
cur_url = reverse("organization_pending_blogs", args=(self.organization_id,self.organization.slug) )
self.delete_blog(request, *args, **kwargs)
cur_url = reverse(
"organization_pending_blogs",
args=(self.organization_id, self.organization.slug),
)
return HttpResponseRedirect(cur_url)
else:
return super().post(request, *args, **kwargs)
@ -1090,15 +1098,13 @@ class EditOrganizationBlog(
def get_title(self):
return _("Edit blog %s") % self.object.title
def create_notification(self,action):
def create_notification(self, action):
blog = BlogPost.objects.get(pk=self.blog_id)
link = reverse(
"edit_organization_blog",
args=[self.organization.id, self.organization.slug, self.blog_id],
)
html = (
f'<a href="{link}">{blog.title} - {self.organization.name}</a>'
)
html = f'<a href="{link}">{blog.title} - {self.organization.name}</a>'
post_authors = blog.authors.all()
posible_user = self.organization.admins.all() | post_authors
for user in posible_user:
@ -1107,11 +1113,11 @@ class EditOrganizationBlog(
notification = Notification(
owner=user,
author=self.request.profile,
category= action,
category=action,
html_link=html,
)
notification.save()
def form_valid(self, form):
with transaction.atomic(), revisions.create_revision():
res = super(EditOrganizationBlog, self).form_valid(form)
@ -1120,6 +1126,7 @@ class EditOrganizationBlog(
self.create_notification("Edit blog")
return res
class PendingBlogs(
LoginRequiredMixin,
TitleMixin,

View file

@ -40,7 +40,7 @@ from judge.models import (
Judge,
Language,
Problem,
ProblemClarification,
ContestProblemClarification,
ProblemGroup,
ProblemTranslation,
ProblemType,
@ -251,7 +251,7 @@ class ProblemDetail(ProblemMixin, SolvedProblemMixin, CommentedDetailView):
context["contest_problem"] = contest_problem
if contest_problem:
clarifications = self.object.clarifications
clarifications = contest_problem.clarifications
context["has_clarifications"] = clarifications.count() > 0
context["clarifications"] = clarifications.order_by("-date")
context["submission_limit"] = contest_problem.max_submissions
@ -665,8 +665,8 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
if self.request.user.is_authenticated:
participation = self.request.profile.current_contest
if participation:
clarifications = ProblemClarification.objects.filter(
problem__in=participation.contest.problems.all()
clarifications = ContestProblemClarification.objects.filter(
problem__in=participation.contest.contest_problems.all()
)
context["has_clarifications"] = clarifications.count() > 0
context["clarifications"] = clarifications.order_by("-date")