Exemplo n.º 1
0
    def pdfupload(self, request, suffix=''):
        """
        Handles PDF upload request from the studio
        """
        try:
            temp_path = self.xblock_path + '/' + uuid4().hex + '.pdf'
            osfs_save_formfile(self.fs, temp_path, request.POST['pdffile'].file)
            with self.fs.open(temp_path, "rb") as f:
                h = hashlib.sha1()
                h.update(f.read())
                self.discussion_docid = h.hexdigest()
                osfs_copy_file(self.fs, temp_path, self.pdf_path)

                mupla_pdfs_folder_path = self.xblock_path + "/" + self.discussion_docid
                mupla_pdf_path = mupla_pdfs_folder_path + "/merged.pdf"
                osfs_mkdir(self.fs, mupla_pdf_path)
                osfs_copy_file(self.fs, self.pdf_path, mupla_pdf_path)

                with self.fs.open(mupla_pdfs_folder_path + "/merged.js", "wb") as f_js:
                    json.dump(self.get_mupla(), f_js)
                    f_js.close()
                f.close()

            return Response(json_body={
                "pdf_url": self.fs.get_url(mupla_pdfs_folder_path+"/merged.pdf", RESOURCE_EXPIRATION_TIME),
                "js_url": self.fs.get_url(mupla_pdfs_folder_path+"/merged.js", RESOURCE_EXPIRATION_TIME),
                "multicolumn_webapp_urls": self.multicolumn_app_urls,
            })
        except Exception:
            print(traceback.format_exc())
            return Response(status=406)
Exemplo n.º 2
0
    def upload_audio(self, request, suffix=''):
        """
        Get audio file from the web app and stores it in the file system.
        POST['data'] is base64 encoded .WAV file stream. POST['fname'] is the filename in the form of <student_id>_<comment_id>.
        For example, 'b7fa14f2df91760225ec682fea1f9da9_2015-06-11T14:21:30.617Z'. Note that the <comment_id> is the time that
        the annotation was created.
        """
        datastr = request.POST['data']
        audio_data = datastr[datastr.index(',')+1:]

        audio_filepath = self.get_audio_filepath(self.group_id, request.POST['fname'])
        osfs_mkdir(self.fs, audio_filepath)

        with self.fs.open(audio_filepath, "wb") as f:
            f.write(audio_data.decode('base64'))
            f.close()
        return Response()
Exemplo n.º 3
0
    def upload_audio(self, request, suffix=''):
        """
        Get audio file from the web app and stores it in the file system.
        POST['data'] is base64 encoded .WAV file stream. POST['fname'] is the filename in the form of <student_id>_<comment_id>.
        For example, 'b7fa14f2df91760225ec682fea1f9da9_2015-06-11T14:21:30.617Z'. Note that the <comment_id> is the time that
        the annotation was created.
        """
        datastr = request.POST['data']
        audio_data = datastr[datastr.index(',') + 1:]

        audio_filepath = self.get_audio_filepath(self.group_id,
                                                 request.POST['fname'])
        osfs_mkdir(self.fs, audio_filepath)

        with self.fs.open(audio_filepath, "wb") as f:
            f.write(audio_data.decode('base64'))
            f.close()
        return Response()
Exemplo n.º 4
0
    def pdfupload(self, request, suffix=''):
        """
        Handles PDF upload request from the studio
        """
        try:
            temp_path = self.xblock_path + '/' + uuid4().hex + '.pdf'
            osfs_save_formfile(self.fs, temp_path,
                               request.POST['pdffile'].file)
            with self.fs.open(temp_path, "rb") as f:
                h = hashlib.sha1()
                h.update(f.read())
                self.discussion_docid = h.hexdigest()
                osfs_copy_file(self.fs, temp_path, self.pdf_path)

                mupla_pdfs_folder_path = self.xblock_path + "/" + self.discussion_docid
                mupla_pdf_path = mupla_pdfs_folder_path + "/merged.pdf"
                osfs_mkdir(self.fs, mupla_pdf_path)
                osfs_copy_file(self.fs, self.pdf_path, mupla_pdf_path)

                with self.fs.open(mupla_pdfs_folder_path + "/merged.js",
                                  "wb") as f_js:
                    json.dump(self.get_mupla(), f_js)
                    f_js.close()
                f.close()

            return Response(
                json_body={
                    "pdf_url":
                    self.fs.get_url(mupla_pdfs_folder_path +
                                    "/merged.pdf", RESOURCE_EXPIRATION_TIME),
                    "js_url":
                    self.fs.get_url(mupla_pdfs_folder_path +
                                    "/merged.js", RESOURCE_EXPIRATION_TIME),
                    "multicolumn_webapp_urls":
                    self.multicolumn_app_urls,
                })
        except Exception:
            print(traceback.format_exc())
            return Response(status=406)