Esempio n. 1
0
 def get(self, request):
     problems = Problem.objects.filter(id__in=request.data["problem_id"])
     for problem in problems:
         if problem.contest:
             ensure_created_by(problem.contest, request.user)
         else:
             ensure_created_by(problem, request.user)
     path = f"/tmp/{rand_str()}.zip"
     with zipfile.ZipFile(path, "w") as zip_file:
         for index, problem in enumerate(problems):
             self.process_one_problem(zip_file=zip_file, user=request.user, problem=problem, index=index + 1)
     delete_files.apply_async((path,), countdown=300)
     resp = FileResponse(open(path, "rb"))
     resp["Content-Type"] = "application/zip"
     resp["Content-Disposition"] = f"attachment;filename=problem-export.zip"
     return resp
Esempio n. 2
0
 def get(self, request):
     problems = Problem.objects.filter(id__in=request.data["problem_id"])
     for problem in problems:
         if problem.contest:
             ensure_created_by(problem.contest, request.user)
         else:
             ensure_created_by(problem, request.user)
     path = f"/tmp/{rand_str()}.zip"
     with zipfile.ZipFile(path, "w") as zip_file:
         for index, problem in enumerate(problems):
             self.process_one_problem(zip_file=zip_file, user=request.user, problem=problem, index=index + 1)
     delete_files.apply_async((path,), countdown=300)
     resp = FileResponse(open(path, "rb"))
     resp["Content-Type"] = "application/zip"
     resp["Content-Disposition"] = f"attachment;filename=problem-export.zip"
     return resp
Esempio n. 3
0
    def get(self, request):
        contest_id = request.GET.get("contest_id")
        if not contest_id:
            return self.error("Parameter error")
        try:
            contest = Contest.objects.get(id=contest_id)
            ensure_created_by(contest, request.user)
        except Contest.DoesNotExist:
            return self.error("Contest does not exist")

        exclude_admin = request.GET.get("exclude_admin") == "1"
        zip_path = self._dump_submissions(contest, exclude_admin)
        delete_files.apply_async((zip_path,), countdown=300)
        resp = FileResponse(open(zip_path, "rb"))
        resp["Content-Type"] = "application/zip"
        resp["Content-Disposition"] = f"attachment;filename={os.path.basename(zip_path)}"
        return resp
Esempio n. 4
0
    def get(self, request):
        contest_id = request.GET.get("contest_id")
        if not contest_id:
            return self.error("Parameter error")
        try:
            contest = Contest.objects.get(id=contest_id)
            ensure_created_by(contest, request.user)
        except Contest.DoesNotExist:
            return self.error("Contest does not exist")

        exclude_admin = request.GET.get("exclude_admin") == "1"
        zip_path = self._dump_submissions(contest, exclude_admin)
        delete_files.apply_async((zip_path,), countdown=300)
        resp = FileResponse(open(zip_path, "rb"))
        resp["Content-Type"] = "application/zip"
        resp["Content-Disposition"] = f"attachment;filename={os.path.basename(zip_path)}"
        return resp