A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
fixes #78
jonaswinkler4548cf08c7a1
diff --git a/src/documents/parsers.py b/src/documents/parsers.pyindex eeaaed886..36ede3cce 100644--- a/src/documents/parsers.py+++ b/src/documents/parsers.py@@ -51,7 +51,11 @@ def get_default_file_extension(mime_type):if mime_type in supported_mime_types:return supported_mime_types[mime_type]- return None+ ext = mimetypes.guess_extension(mime_type)+ if ext:+ return ext+ else:+ return ""def is_file_ext_supported(ext):diff --git a/src/documents/tests/test_document_model.py b/src/documents/tests/test_document_model.pyindex 49e7139c8..8764c7ec8 100644--- a/src/documents/tests/test_document_model.py+++ b/src/documents/tests/test_document_model.py@@ -1,6 +1,6 @@-import osimport shutilimport tempfile+from datetime import datetimefrom pathlib import Pathfrom unittest import mock@@ -44,3 +44,23 @@ class TestDocument(TestCase):mock_unlink.assert_any_call(file_path)mock_unlink.assert_any_call(thumb_path)self.assertEqual(mock_unlink.call_count, 2)++ def test_file_name(self):++ doc = Document(mime_type="application/pdf", title="test", created=datetime(2020, 12, 25))+ self.assertEqual(doc.file_name, "20201225-test.pdf")++ def test_file_name_jpg(self):++ doc = Document(mime_type="image/jpeg", title="test", created=datetime(2020, 12, 25))+ self.assertEqual(doc.file_name, "20201225-test.jpg")++ def test_file_name_unknown(self):++ doc = Document(mime_type="application/zip", title="test", created=datetime(2020, 12, 25))+ self.assertEqual(doc.file_name, "20201225-test.zip")++ def test_file_name_invalid(self):++ doc = Document(mime_type="image/jpegasd", title="test", created=datetime(2020, 12, 25))+ self.assertEqual(doc.file_name, "20201225-test")