Ejemplo n.º 1
0
def export_submissions_view(request):
    if request.method == 'POST':
        form = ExportSubmissionsForm(request, request.POST)
        if form.is_valid():
            round = form.cleaned_data['round']
            only_final = form.cleaned_data['only_final']
            collector = SubmissionsWithUserDataCollector(request.contest,
                round=round, only_final=only_final)
            # TemporaryFile promises removal of the file when it is closed.
            # Note that we cannot use with, because we want to keep it beyond
            # this function call.
            tmp_file = tempfile.TemporaryFile()
            build_submissions_archive(tmp_file, collector)
            # We send a large file with django. Usually it isn't a good idea,
            # but letting the web server do it leads to problems with when to
            # delete this file and from where.
            tmp_file.seek(0, os.SEEK_SET)  # go to the beginning of the file
            response = FileResponse(tmp_file)
            response['Content-Type'] = 'application/gzip'
            response['Content-Disposition'] = ('attachment; filename="%s.tgz"'
                % request.contest.id)
            return response
    else:
        form = ExportSubmissionsForm(request)
    return TemplateResponse(request,
        'similarsubmits/export_submissions.html',
        {'form': form})
Ejemplo n.º 2
0
def export_submissions_view(request):
    if request.method == 'POST':
        form = ExportSubmissionsForm(request, request.POST)
        if form.is_valid():
            round = form.cleaned_data['round']
            only_final = form.cleaned_data['only_final']
            collector = SubmissionsWithUserDataCollector(request.contest,
                round=round, only_final=only_final)
            # TemporaryFile promises removal of the file when it is closed.
            # Note that we cannot use with, because we want to keep it beyond
            # this function call.
            tmp_file = tempfile.TemporaryFile()
            build_submissions_archive(tmp_file, collector)
            # We send a large file with django. Usually it isn't a good idea,
            # but letting the web server do it leads to problems with when to
            # delete this file and from where.
            tmp_file.seek(0, os.SEEK_SET)  # go to the beginning of the file
            response = FileResponse(tmp_file)
            response['Content-Disposition'] = ('attachment; filename="%s.tgz"'
                % request.contest.id)
            return response
    else:
        form = ExportSubmissionsForm(request)
    return TemplateResponse(request,
        'similarsubmits/export_submissions.html',
        {'form': form})
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        contest = Contest.objects.get(id=options['contest_id'])

        round_id = options.get('round_id')
        if round_id:
            round = Round.objects.get(id=round_id)
            if round.contest != contest:
                raise CommandError("This round doesn't belong to the chosen contest.")
        else:
            round = None

        collector = SubmissionsWithUserDataCollector(
            contest, round=round, only_final=not options.get('all')
        )
        with open(options['out_file'], 'wb') as f:
            build_submissions_archive(f, collector)
Ejemplo n.º 4
0
    def handle(self, *args, **options):
        contest = Contest.objects.get(id=options['contest_id'])

        round_id = options.get('round_id')
        if round_id:
            round = Round.objects.get(id=round_id)
            if round.contest != contest:
                raise CommandError(
                    "This round doesn't belong to the chosen contest.")
        else:
            round = None

        collector = SubmissionsWithUserDataCollector(contest, round=round,
            only_final=not options.get('all'))
        with open(options['out_file'], 'w') as f:
            build_submissions_archive(f, collector)
Ejemplo n.º 5
0
    def handle(self, *args, **options):
        if len(args) != 2:
            raise CommandError("Exactly two arguments are required.")

        contest_id = args[0]
        out_file = args[1]

        contest = Contest.objects.get(id=contest_id)

        round_id = options.get('round_id')
        if round_id:
            round = Round.objects.get(id=round_id)
            if round.contest != contest:
                raise CommandError(
                    "This round doesn't belong to the chosen contest.")
        else:
            round = None

        collector = SubmissionsWithUserDataCollector(contest, round=round,
            only_final=not options.get('all'))
        build_submissions_archive(out_file, collector)
Ejemplo n.º 6
0
    def handle(self, *args, **options):
        if len(args) != 2:
            raise CommandError("Exactly two arguments are required.")

        contest_id = args[0]
        out_file = args[1]

        contest = Contest.objects.get(id=contest_id)

        round_id = options.get('round_id')
        if round_id:
            round = Round.objects.get(id=round_id)
            if round.contest != contest:
                raise CommandError(
                    "This round doesn't belong to the chosen contest.")
        else:
            round = None

        collector = SubmissionsWithUserDataCollector(
            contest, round=round, only_final=not options.get('all'))
        with open(out_file, 'w') as f:
            build_submissions_archive(f, collector)