示例#1
0
 def download_submissions(self, request, suffix=''):  # pylint: disable=unused-argument
     """
     Api for downloading zip file which consist of all students submissions.
     """
     # pylint: disable=no-member
     require(self.is_course_staff())
     user = self.get_real_user()
     require(user)
     try:
         zip_file_path = get_zip_file_path(user.username,
                                           self.block_course_id,
                                           self.block_id, self.location)
         zip_file_name = get_zip_file_name(user.username,
                                           self.block_course_id,
                                           self.block_id)
         return Response(app_iter=file_contents_iter(zip_file_path),
                         content_type='application/zip',
                         content_disposition="attachment; filename=" +
                         zip_file_name)
     except OSError:
         return Response(
             "Sorry, submissions cannot be found. Press Collect ALL Submissions button or"
             " contact {} if you issue is consistent".format(
                 settings.TECH_SUPPORT_EMAIL),
             status_code=404)
示例#2
0
文件: sga.py 项目: mitodl/edx-sga
 def download(self, path, mime_type, filename, require_staff=False):
     """
     Return a file from storage and return in a Response.
     """
     try:
         return Response(
             app_iter=file_contents_iter(path),
             content_type=mime_type,
             content_disposition="attachment; filename*=UTF-8''" + urllib.quote(filename.encode('utf-8'))
         )
     except IOError:
         if require_staff:
             return Response(
                 "Sorry, assignment {} cannot be found at"
                 " {}. Please contact {}".format(
                     filename.encode('utf-8'), path, settings.TECH_SUPPORT_EMAIL
                 ),
                 status_code=404
             )
         return Response(
             "Sorry, the file you uploaded, {}, cannot be"
             " found. Please try uploading it again or contact"
             " course staff".format(filename.encode('utf-8')),
             status_code=404
         )
示例#3
0
 def download(self, path, mime_type, filename, require_staff=False):
     """
     Return a file from storage and return in a Response.
     """
     try:
         content_disposition = "attachment; filename*=UTF-8''"
         content_disposition += six.moves.urllib.parse.quote(filename.encode('utf-8'))
         output = Response(
             app_iter=file_contents_iter(path),
             content_type=mime_type,
             content_disposition=content_disposition
         )
         return output
     except IOError:
         if require_staff:
             return Response(
                 "Sorry, assignment {} cannot be found at"
                 " {}. Please contact {}".format(
                     filename.encode('utf-8'), path, settings.TECH_SUPPORT_EMAIL
                 ),
                 status_code=404
             )
         return Response(
             "Sorry, the file you uploaded, {}, cannot be"
             " found. Please try uploading it again or contact"
             " course staff".format(filename.encode('utf-8')),
             status_code=404
         )
示例#4
0
文件: sga.py 项目: mitodl/edx-sga
 def download_submissions(self, request, suffix=''):  # pylint: disable=unused-argument
     """
     Api for downloading zip file which consist of all students submissions.
     """
     require(self.is_course_staff())
     user = self.get_real_user()
     require(user)
     try:
         zip_file_path = get_zip_file_path(
             user.username,
             self.block_course_id,
             self.block_id,
             self.location
         )
         zip_file_name = get_zip_file_name(
             user.username,
             self.block_course_id,
             self.block_id
         )
         return Response(
             app_iter=file_contents_iter(zip_file_path),
             content_type='application/zip',
             content_disposition="attachment; filename=" + zip_file_name.encode('utf-8')
         )
     except IOError:
         return Response(
             "Sorry, submissions cannot be found. Press Collect ALL Submissions button or"
             " contact {} if you issue is consistent".format(settings.TECH_SUPPORT_EMAIL),
             status_code=404
         )