def add_template(description, filename, reference): with open(os.path.join(resource_dir, "server", filename), "rb") as f: template_id = documents_service.save_template(f, filename) documents_service.update_template_description( template_id, description, filename, reference)
def upload_template_document4(self, file_id, encoding_safe_filename, uploaded_file): """ Create or replace a new template document. :param encoding_safe_filename: :param uploaded_file: :param doc_id: :return: """ mainlog.debug("upload_template_document4") doc_id = int(file_id) if doc_id == 0: mainlog.debug("upload_template_document4 : upload") doc_id = documents_service.save_template(uploaded_file.file, encoding_safe_filename) elif doc_id > 0: mainlog.debug( "upload_template_document4 : replace doc_id={}".format( doc_id)) doc_id = documents_service.replace_template( doc_id, uploaded_file.file, encoding_safe_filename) return str(doc_id)
def test_copy_template(self): tmp = self._make_tmp_file() tpl_id = documents_service.save_template(tmp[0], 'zulu') self._clear_tmp_file(*tmp) doc_id = documents_service.copy_template_to_document(tpl_id) assert documents_service.find_by_id(doc_id) assert documents_service.find_by_id(tpl_id)
def register_horse_template_offline(description, full_path, ref): """ Register a file in the template library, will do it by accessing the server code directly instead of via HTTP. :param description: :param full_path: :param ref: :return: None """ from koi.doc_manager.documents_service import documents_service with open(full_path,'rb') as fh: doc_id = documents_service.reference_to_document_id(ref) if not doc_id: doc_id = documents_service.save_template(fh, os.path.basename(full_path)) documents_service.update_template_description(doc_id, description, os.path.basename(full_path), ref) else: mainlog.debug("I didn't add {} with reference {} because it's already there".format(full_path,ref))
def test_add_delete_template(self): t = documents_service.all_templates() assert len(t) == 0 tmp = self._make_tmp_file() tpl_id = documents_service.save_template(tmp[0], 'zulu.tpl') self._clear_tmp_file(*tmp) t = documents_service.all_templates() assert len(t) == 1 d = documents_service.find_by_id(tpl_id) assert d.filename == "zulu.tpl" assert "koimes_{}_{}".format(tpl_id,"zulu.tpl") in d.server_location assert d.file_size == 8 assert d.upload_date.year == datetime.today().year assert d.upload_date.month == datetime.today().month assert d.upload_date.day == datetime.today().day documents_service.delete(tpl_id) t = documents_service.all_templates() assert len(t) == 0
def upload_template_document2(self, encoding_safe_filename, uploaded_file): # DEPRECATED !!! file_id = documents_service.save_template(uploaded_file.file, encoding_safe_filename) return str(file_id)