Change live notification to polling
This commit is contained in:
parent
2539b3e071
commit
425354a2de
7 changed files with 70 additions and 58 deletions
|
@ -11,9 +11,7 @@ from django.db.models.functions import Coalesce
|
|||
from django.urls import reverse
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils import timezone
|
||||
|
||||
from judge import event_poster as event
|
||||
from judge.fulltext import SearchQuerySet
|
||||
from judge.models.profile import Organization, Profile
|
||||
from judge.models.runtime import Language
|
||||
|
@ -409,26 +407,6 @@ class ProblemClarification(models.Model):
|
|||
description = models.TextField(verbose_name=_('clarification body'))
|
||||
date = models.DateTimeField(verbose_name=_('clarification timestamp'), auto_now_add=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(ProblemClarification, self).save(*args, **kwargs)
|
||||
|
||||
if event.real:
|
||||
from judge.models import ContestProblem
|
||||
|
||||
now = timezone.now()
|
||||
# List all ongoing contests containing this problem
|
||||
contest_problems = ContestProblem.objects.filter(
|
||||
contest__start_time__lte=now,
|
||||
contest__end_time__gt=now,
|
||||
problem=self.problem).values_list('order', 'contest')
|
||||
|
||||
for order, contest_id in contest_problems.iterator():
|
||||
event.post('contest_clarification_' + str(contest_id), {
|
||||
'problem_label': order,
|
||||
'problem_name': self.problem.name,
|
||||
'problem_code': self.problem.code,
|
||||
'body': self.description
|
||||
})
|
||||
|
||||
class LanguageLimit(models.Model):
|
||||
problem = models.ForeignKey(Problem, verbose_name=_('problem'), related_name='language_limits', on_delete=CASCADE)
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
|
|||
from django.db import IntegrityError
|
||||
from django.db.models import Case, Count, F, FloatField, IntegerField, Max, Min, Q, Sum, Value, When
|
||||
from django.db.models.expressions import CombinedExpression
|
||||
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseRedirect
|
||||
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseRedirect, JsonResponse
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.template.defaultfilters import date as date_filter
|
||||
from django.urls import reverse, reverse_lazy
|
||||
|
@ -915,4 +915,40 @@ class NewContestClarificationView(ContestMixin, TitleMixin, SingleObjectFormView
|
|||
context = super(NewContestClarificationView, self).get_context_data(**kwargs)
|
||||
context['problems'] = ContestProblem.objects.filter(contest=self.object)\
|
||||
.order_by('order')
|
||||
return context
|
||||
return context
|
||||
|
||||
|
||||
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():
|
||||
raise Http404()
|
||||
|
||||
polling_time = 1 # minute
|
||||
last_one_minute = last_five_minutes = timezone.now()-timezone.timedelta(minutes=polling_time)
|
||||
|
||||
queryset = list(ProblemClarification.objects.filter(
|
||||
problem__in=self.object.problems.all(),
|
||||
date__gte=last_one_minute
|
||||
).values('problem', 'problem__name', 'description'))
|
||||
|
||||
problems = list(ContestProblem.objects.filter(contest=self.object)\
|
||||
.order_by('order').values('problem'))
|
||||
problems = [i['problem'] for i in problems]
|
||||
for cla in queryset:
|
||||
cla['order'] = self.object.get_label_for_problem(problems.index(cla['problem']))
|
||||
|
||||
return JsonResponse(queryset, safe=False, json_dumps_params={'ensure_ascii': False})
|
||||
|
|
|
@ -25,7 +25,6 @@ from django.views.generic import ListView, View
|
|||
from django.views.generic.base import TemplateResponseMixin
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
|
||||
from judge import event_poster as event
|
||||
from judge.comments import CommentedDetailView
|
||||
from judge.forms import ProblemCloneForm, ProblemSubmitForm
|
||||
from judge.models import ContestProblem, ContestSubmission, Judge, Language, Problem, ProblemGroup, \
|
||||
|
@ -174,7 +173,6 @@ class ProblemDetail(ProblemMixin, SolvedProblemMixin, CommentedDetailView):
|
|||
|
||||
if contest_problem:
|
||||
clarifications = self.object.clarifications
|
||||
context['last_msg'] = event.last()
|
||||
context['has_clarifications'] = clarifications.count() > 0
|
||||
context['clarifications'] = clarifications.order_by('-date')
|
||||
context['submission_limit'] = contest_problem.max_submissions
|
||||
|
@ -437,7 +435,6 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
|||
context['hot_problems'] = hot_problems(timedelta(days=1), 7)
|
||||
context['point_start'], context['point_end'], context['point_values'] = self.get_noui_slider_points()
|
||||
else:
|
||||
context['last_msg'] = event.last()
|
||||
context['hot_problems'] = None
|
||||
context['point_start'], context['point_end'], context['point_values'] = 0, 0, {}
|
||||
context['hide_contest_scoreboard'] = self.contest.scoreboard_visibility in \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue