diff --git a/dmoj/urls.py b/dmoj/urls.py index 3037741..fcd24b6 100644 --- a/dmoj/urls.py +++ b/dmoj/urls.py @@ -119,6 +119,7 @@ urlpatterns = [ url(r'^/pdf$', problem.ProblemPdfView.as_view(), name='problem_pdf'), url(r'^/pdf/(?P[a-z-]+)$', problem.ProblemPdfView.as_view(), name='problem_pdf'), url(r'^/clone', problem.ProblemClone.as_view(), name='problem_clone'), + url(r'^/downloadAC$', problem.download_submissions, name='download_submissions'), url(r'^/submit$', problem.problem_submit, name='problem_submit'), url(r'^/resubmit/(?P\d+)$', problem.problem_submit, name='problem_submit'), diff --git a/judge/views/problem.py b/judge/views/problem.py index 4c3246d..1403b3c 100644 --- a/judge/views/problem.py +++ b/judge/views/problem.py @@ -4,6 +4,7 @@ import shutil from datetime import timedelta from operator import itemgetter from random import randrange +import zipfile, tempfile from django.conf import settings from django.contrib.auth.decorators import login_required @@ -676,4 +677,22 @@ class ProblemClone(ProblemMixin, PermissionRequiredMixin, TitleMixin, SingleObje problem.language_limits.set(language_limits) problem.types.set(types) - return HttpResponseRedirect(reverse('admin:judge_problem_change', args=(problem.id,))) \ No newline at end of file + return HttpResponseRedirect(reverse('admin:judge_problem_change', args=(problem.id,))) + + +def download_submissions(request, problem): + submissions = Submission.objects.filter(problem__code=problem, result='AC') + + with tempfile.SpooledTemporaryFile() as tmp: + with zipfile.ZipFile(tmp, 'w', zipfile.ZIP_DEFLATED) as archive: + for submission in submissions: + file_name = str(submission.id) + '.' + str(submission.language.key) + archive.writestr(file_name, submission.source.source) + + # Reset file pointer + tmp.seek(0) + + # Write file data to response + response = HttpResponse(tmp.read(), content_type='application/x-zip-compressed') + response['Content-Disposition'] = 'attachment; filename="%s"' % (str(problem) + '_submissions.zip') + return response \ No newline at end of file diff --git a/templates/problem/problem.html b/templates/problem/problem.html index 65bd6a3..5e6b3ce 100644 --- a/templates/problem/problem.html +++ b/templates/problem/problem.html @@ -126,6 +126,12 @@ {% endif %}
{{ _('All submissions') }}
{{ _('Best submissions') }}
+ {% if request.user.is_superuser %} +
+ {{ _('Download AC submissions') }} +
+ {% endif %} + {% if editorial and editorial.is_public and not (request.user.is_authenticated and request.profile.current_contest) %}