def delete_document(document_id,user): document = ProjectDocument.objects.get(int(document_id)) document_name = '--' file_info = FileInfo.objects.get(document.FileID) if file_info: document_name = file_info.FileName if document.Type == 1: child_documents = ProjectDocument.objects.get_child_documents(document.id) if len(child_documents)>0: DocumentService.delete_child_document(child_documents) document.delete() else: file_info = FileInfo.objects.get(document.FileID) file_info.delete() document.delete() if document.Type == 2: file_info = FileInfo.objects.get(document.FileID) FileInfoService.delete_value(file_info.id, ProjectExcelDocumentMongoFile) document.delete() if document.Type == 3: file_info = FileInfo.objects.get(document.FileID) FileInfoService.delete_value(file_info.id, ProjectDocumentMongoFile) document.delete() DocumentService.log_delete_activity(user,document,document_name) pass
def delete_child_document(child_documents): for document in child_documents: if document.Type == 1: childs = ProjectDocument.objects.get_child_documents(document.id) if len(childs)>0: DocumentService.delete_child_document(childs) document.delete() else: file_info = FileInfo.objects.get(document.FileID) file_info.delete() document.delete() if document.Type == 2: file_info = FileInfo.objects.get(document.FileID) FileInfoService.delete_value(file_info.id,ProjectExcelDocumentMongoFile) document.delete() if document.Type == 3: file_info = FileInfo.objects.get(document.FileID) FileInfoService.delete_value(file_info.id,ProjectDocumentMongoFile) document.delete() return 0