Esempio n. 1
0
    def download_assignment(self, request, suffix=''):
        # pylint: disable=unused-argument
        """
        Downloads the student's answer file from storage api and then returns a response
        """
        try:
            file_descriptor = storage.access_data(
                str(self.course_id),
                str(self.xmodule_runtime.anonymous_student_id),
                str(self.location.block_id))
        except PersonValueError:
            log.info("storage api download failed:")
            log.info("peson argument cant be an empty string")
        except DepartmentValueError:
            log.info("storage api download failed:")
            log.info("department argument cant be an empty string")
        except QualifierValueError:
            log.info("storage api download failed:")
            log.info("qualifier argument cant be an empty string")
        except BucketValueError:
            log.info("storage api download failed:")
            log.info("invalid bucket key argument")
        except S3ValueError:
            log.info("storage api download failed:")
            log.info("invalid S3 credentials")
        except SocketValueError:
            log.info("storage api download failed:")
            log.info("invalid host")

        app_iter = iter(partial(file_descriptor.read, BLOCK_SIZE), '')

        return Response(app_iter=app_iter,
                        content_type=self.raw_answer["mimetype"],
                        content_disposition="attachment; filename=" +
                        self.raw_answer["filename"].encode('utf-8'))
Esempio n. 2
0
 def download_solution(self, request, suffix=''):
     # pylint: disable=unused-argument
     """
     Downloads the solution file from storage api and then returns a response
     """
     log.info("download_solution called")
     try:
         file_descriptor = storage.access_data(str(self.course_id),
                                               "solution",
                                               str(self.location.block_id))
         log.info("file_descriptor is:")
         log.info(file_descriptor)
         if not file_descriptor:
             log.info("storage api download failed:")
             log.info("file doesn't exist")
             return
         log.info("download through storage api successful")
         app_iter = iter(partial(file_descriptor.read, BLOCK_SIZE), '')
         return Response(app_iter=app_iter,
                         content_type=self.raw_solution["mimetype"],
                         content_disposition="attachment; filename=" +
                         self.raw_solution["filename"].encode('utf-8'))
     except storage.PersonValueError:
         log.info("storage api download failed:")
         log.info("peson argument cant be an empty string")
         return
     except DepartmentValueError:
         log.info("storage api download failed:")
         log.info("department argument cant be an empty string")
         return
     except QualifierValueError:
         log.info("storage api download failed:")
         log.info("qualifier argument cant be an empty string")
         return
     except BucketValueError:
         log.info("storage api download failed:")
         log.info("invalid bucket key argument")
         return
     except S3ValueError:
         log.info("storage api download failed:")
         log.info("invalid S3 credentials")
         return
     except SocketValueError:
         log.info("storage api download failed:")
         log.info("invalid host")
         return