def load_rrt(self): file_path = os.path.join(app.root_path, 'static', 'reference', 'rrt_documents.xlsx') file = open(file_path, "rb") FileService.add_reference_file(FileService.DOCUMENT_LIST, binary_data=file.read(), content_type=CONTENT_TYPES['xls']) file.close() category = WorkflowSpecCategoryModel( id=0, name='research_rampup_category', display_name='Research Ramp-up Category', display_order=0) db.session.add(category) db.session.commit() self.create_spec( id="rrt_top_level_workflow", name="rrt_top_level_workflow", display_name="Top Level Workflow", description="Does nothing, we don't use the master workflow here.", category_id=None, master_spec=True) self.create_spec( id="research_rampup", name="research_rampup", display_name="Research Ramp-up Toolkit", description="Process for creating a new research ramp-up request.", category_id=0, master_spec=False)
def create_reference_document(self): file_path = os.path.join(app.root_path, 'static', 'reference', 'irb_documents.xlsx') file = open(file_path, "rb") FileService.add_reference_file(FileService.DOCUMENT_LIST, binary_data=file.read(), content_type=CONTENT_TYPES['xls']) file.close()
def set_reference_file(name): """Uses the file service to manage reference-files. They will be used in script tasks to compute values.""" if 'file' not in connexion.request.files: raise ApiError('invalid_file', 'Expected a file named "file" in the multipart form request', status_code=400) file = connexion.request.files['file'] name_extension = FileService.get_extension(name) file_extension = FileService.get_extension(file.filename) if name_extension != file_extension: raise ApiError('invalid_file_type', "The file you uploaded has an extension '%s', but it should have an extension of '%s' " % (file_extension, name_extension)) file_models = FileService.get_files(name=name, is_reference=True) if len(file_models) == 0: file_model = FileService.add_reference_file(name, file.content_type, file.stream.read()) else: file_model = file_models[0] FileService.update_file(file_models[0], file.stream.read(), file.content_type) return FileSchema().dump(to_file_api(file_model))