A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Simplifies file upload naming to use the document name, instead in needing to keep it around
Trenton Holmesa88b318d7dcb
diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.pyindex dace48578..4547288d2 100644--- a/src/documents/tests/test_api.py+++ b/src/documents/tests/test_api.py@@ -7,6 +7,7 @@ import tempfileimport urllib.requestimport uuidimport zipfile+from pathlib import Pathfrom unittest import mockfrom unittest.mock import MagicMock@@ -808,7 +809,9 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):m.assert_called_once()args, kwargs = m.call_args- self.assertEqual(kwargs["override_filename"], "simple.pdf")+ file_path = Path(args[0])+ self.assertEqual(file_path.name, "simple.pdf")+ self.assertIn(Path(settings.SCRATCH_DIR), file_path.parents)self.assertIsNone(kwargs["override_title"])self.assertIsNone(kwargs["override_correspondent_id"])self.assertIsNone(kwargs["override_document_type_id"])@@ -833,7 +836,9 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):m.assert_called_once()args, kwargs = m.call_args- self.assertEqual(kwargs["override_filename"], "simple.pdf")+ file_path = Path(args[0])+ self.assertEqual(file_path.name, "simple.pdf")+ self.assertIn(Path(settings.SCRATCH_DIR), file_path.parents)self.assertIsNone(kwargs["override_title"])self.assertIsNone(kwargs["override_correspondent_id"])self.assertIsNone(kwargs["override_document_type_id"])diff --git a/src/documents/views.py b/src/documents/views.pyindex 46cf06cfd..147dd2e07 100644--- a/src/documents/views.py+++ b/src/documents/views.py@@ -7,6 +7,7 @@ import urllibimport uuidimport zipfilefrom datetime import datetime+from pathlib import Pathfrom time import mktimefrom unicodedata import normalizefrom urllib.parse import quote@@ -623,20 +624,18 @@ class PostDocumentView(GenericAPIView):os.makedirs(settings.SCRATCH_DIR, exist_ok=True)- with tempfile.NamedTemporaryFile(- prefix="paperless-upload-",- dir=settings.SCRATCH_DIR,- delete=False,- ) as f:- f.write(doc_data)- os.utime(f.name, times=(t, t))- temp_filename = f.name+ temp_file_path = Path(tempfile.mkdtemp(dir=settings.SCRATCH_DIR)) / Path(+ doc_name,+ )++ temp_file_path.write_bytes(doc_data)++ os.utime(temp_file_path, times=(t, t))task_id = str(uuid.uuid4())async_task = consume_file.delay(- temp_filename,- override_filename=doc_name,+ temp_file_path,override_title=title,override_correspondent_id=correspondent_id,override_document_type_id=document_type_id,