def get(self, request, event): try: zip_path = get_export_zip_path(self.request.event) response = FileResponse(open(zip_path, "rb"), as_attachment=True) except Exception as e: messages.error( request, _("Could not find the current export, please try to regenerate it. ({error})" ).format(error=str(e)), ) return redirect(self.request.event.orga_urls.schedule_export) response[ "Content-Disposition"] = "attachment; filename=" + safe_filename( zip_path.name) return response
def test_safe_filename(filename, expected): assert safe_filename(filename) == expected