A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
fixes #591
jonaswinklerd64818b46cc2
diff --git a/src/documents/management/commands/document_archiver.py b/src/documents/management/commands/document_archiver.pyindex 0d3a5e82d..6a6056ed7 100644--- a/src/documents/management/commands/document_archiver.py+++ b/src/documents/management/commands/document_archiver.py@@ -31,6 +31,11 @@ def handle_document(document_id):parser_class = get_parser_class_for_mime_type(mime_type)+ if not parser_class:+ logger.error(f"No parser found for mime type {mime_type}, cannot "+ f"archive document {document} (ID: {document_id})")+ return+parser = parser_class(logging_group=uuid.uuid4())try:@@ -66,11 +71,12 @@ def handle_document(document_id):document.archive_path)shutil.move(thumbnail, document.thumbnail_path)- with AsyncWriter(index.open_index()) as writer:- index.update_document(writer, document)+ with index.open_index_writer() as writer:+ index.update_document(writer, document)except Exception as e:- logger.exception(f"Error while parsing document {document}")+ logger.exception(f"Error while parsing document {document} "+ f"(ID: {document_id})")finally:parser.cleanup()diff --git a/src/documents/tests/test_management.py b/src/documents/tests/test_management.pyindex 40eaaf277..f7beb8907 100644--- a/src/documents/tests/test_management.py+++ b/src/documents/tests/test_management.py@@ -49,6 +49,21 @@ class TestArchiver(DirectoriesMixin, TestCase):self.assertTrue(filecmp.cmp(sample_file, doc.source_path))self.assertEqual(doc.archive_filename, "none/A.pdf")+ def test_unknown_mime_type(self):+ doc = self.make_models()+ doc.mime_type = "sdgfh"+ doc.save()+ shutil.copy(sample_file, doc.source_path)++ handle_document(doc.pk)++ doc = Document.objects.get(id=doc.id)++ self.assertIsNotNone(doc.checksum)+ self.assertIsNone(doc.archive_checksum)+ self.assertIsNone(doc.archive_filename)+ self.assertTrue(os.path.isfile(doc.source_path))+@override_settings(PAPERLESS_FILENAME_FORMAT="{title}")def test_naming_priorities(self):doc1 = Document.objects.create(checksum="A", title="document", content="first document", mime_type="application/pdf", filename="document.pdf")