|
5 | 5 | from django.contrib.auth.mixins import PermissionRequiredMixin |
6 | 6 | from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseRedirect |
7 | 7 | from django.urls import reverse |
| 8 | +from django.utils import timezone |
8 | 9 | from django.utils.html import escape, format_html |
9 | 10 | from django.utils.safestring import mark_safe |
10 | 11 | from django.utils.translation import gettext as _, ngettext |
11 | 12 | from django.views.generic import DetailView |
12 | 13 | from django.views.generic.detail import BaseDetailView |
13 | 14 |
|
14 | 15 | from judge.models import Language, Submission |
15 | | -from judge.tasks import apply_submission_filter, rejudge_problem_filter, rescore_problem |
| 16 | +from judge.tasks import apply_submission_filter, archive_locked_submissions, rejudge_problem_filter, rescore_problem |
16 | 17 | from judge.utils.celery import redirect_to_task_status |
17 | 18 | from judge.utils.views import TitleMixin |
18 | 19 | from judge.views.problem import ProblemMixin |
@@ -56,13 +57,26 @@ def get_content_title(self): |
56 | 57 |
|
57 | 58 | def get_context_data(self, **kwargs): |
58 | 59 | context = super().get_context_data(**kwargs) |
| 60 | + context['locked_count'] = \ |
| 61 | + self.object.submission_set.filter(is_archived=False, locked_after__lt=timezone.now()).count() |
59 | 62 | context['submission_count'] = self.object.submission_set.count() |
60 | 63 | context['languages'] = [(lang_id, short_name or key) for lang_id, key, short_name in |
61 | 64 | Language.objects.values_list('id', 'key', 'short_name')] |
62 | 65 | context['results'] = sorted(map(itemgetter(0), Submission.RESULT)) |
63 | 66 | return context |
64 | 67 |
|
65 | 68 |
|
| 69 | +class ArchiveLockedSubmissionsView(PermissionRequiredMixin, ManageProblemSubmissionActionMixin, BaseDetailView): |
| 70 | + permission_required = 'judge.archive_submission' |
| 71 | + |
| 72 | + def perform_action(self): |
| 73 | + status = archive_locked_submissions.delay(self.object.id) |
| 74 | + return redirect_to_task_status( |
| 75 | + status, message=_('Archiving all locked submissions for %s...') % (self.object.name,), |
| 76 | + redirect=reverse('problem_submissions_archive_success', args=[self.object.code, status.id]), |
| 77 | + ) |
| 78 | + |
| 79 | + |
66 | 80 | class BaseRejudgeSubmissionsView(PermissionRequiredMixin, ManageProblemSubmissionActionMixin, BaseDetailView): |
67 | 81 | permission_required = 'judge.rejudge_submission_lot' |
68 | 82 |
|
@@ -113,6 +127,15 @@ def perform_action(self): |
113 | 127 | ) |
114 | 128 |
|
115 | 129 |
|
| 130 | +def archive_success(request, problem, task_id): |
| 131 | + count = AsyncResult(task_id).result |
| 132 | + if not isinstance(count, int): |
| 133 | + raise Http404() |
| 134 | + messages.success(request, ngettext('%d submission was successfully archived.', |
| 135 | + '%d submissions were successfully archived.', count) % (count,)) |
| 136 | + return HttpResponseRedirect(reverse('problem_manage_submissions', args=[problem])) |
| 137 | + |
| 138 | + |
116 | 139 | def rejudge_success(request, problem, task_id): |
117 | 140 | count = AsyncResult(task_id).result |
118 | 141 | if not isinstance(count, int): |
|
0 commit comments