A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
fixes an issue with paperless not assigning metadata when FILENAME_FORMAT is specified and resolves an invalid warning about missing files fixes #67
jonaswinklera27daaebe934
diff --git a/src/documents/consumer.py b/src/documents/consumer.pyindex a7afca89d..46c943d6b 100755--- a/src/documents/consumer.py+++ b/src/documents/consumer.py@@ -167,6 +167,11 @@ class Consumer(LoggingMixin):self._write(document, self.path, document.source_path)self._write(document, thumbnail, document.thumbnail_path)+ # Afte performing all database operations and moving files+ # into place, tell paperless where the file is.+ document.filename = generate_filename(document)+ document.save()+# Delete the file only if it was successfully consumedself.log("debug", "Deleting file {}".format(self.path))os.unlink(self.path)@@ -217,12 +222,6 @@ class Consumer(LoggingMixin):self.apply_overrides(document)- document.filename = generate_filename(document)-- # We need to save the document twice, since we need the PK of the- # document in order to create its filename above.- document.save()-return documentdef apply_overrides(self, document):diff --git a/src/documents/tests/samples/originals/0000001.pdf b/src/documents/tests/samples/documents/originals/0000001.pdfsimilarity index 100%rename from src/documents/tests/samples/originals/0000001.pdfrename to src/documents/tests/samples/documents/originals/0000001.pdfdiff --git a/src/documents/tests/samples/originals/0000002.pdf.gpg b/src/documents/tests/samples/documents/originals/0000002.pdf.gpgsimilarity index 100%rename from src/documents/tests/samples/originals/0000002.pdf.gpgrename to src/documents/tests/samples/documents/originals/0000002.pdf.gpgdiff --git a/src/documents/tests/samples/thumb/0000001.png b/src/documents/tests/samples/documents/thumbnails/0000001.pngsimilarity index 100%rename from src/documents/tests/samples/thumb/0000001.pngrename to src/documents/tests/samples/documents/thumbnails/0000001.pngdiff --git a/src/documents/tests/samples/thumb/0000002.png.gpg b/src/documents/tests/samples/documents/thumbnails/0000002.png.gpgsimilarity index 100%rename from src/documents/tests/samples/thumb/0000002.png.gpgrename to src/documents/tests/samples/documents/thumbnails/0000002.png.gpgdiff --git a/src/documents/tests/test_management_decrypt.py b/src/documents/tests/test_management_decrypt.pyindex 326276389..8f41e076f 100644--- a/src/documents/tests/test_management_decrypt.py+++ b/src/documents/tests/test_management_decrypt.py@@ -34,8 +34,8 @@ class TestDecryptDocuments(TestCase):PASSPHRASE="test").enable()- shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "originals", "0000002.pdf.gpg"), os.path.join(originals_dir, "0000002.pdf.gpg"))- shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "thumb", "0000002.png.gpg"), os.path.join(thumb_dir, "0000002.png.gpg"))+ shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "originals", "0000002.pdf.gpg"), os.path.join(originals_dir, "0000002.pdf.gpg"))+ shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "thumbnails", "0000002.png.gpg"), os.path.join(thumb_dir, "0000002.png.gpg"))Document.objects.create(checksum="9c9691e51741c1f4f41a20896af31770", title="wow", filename="0000002.pdf.gpg", id=2, mime_type="application/pdf", storage_type=Document.STORAGE_TYPE_GPG)diff --git a/src/documents/tests/test_management_exporter.py b/src/documents/tests/test_management_exporter.pyindex c8d1490d2..18171af75 100644--- a/src/documents/tests/test_management_exporter.py+++ b/src/documents/tests/test_management_exporter.py@@ -1,6 +1,7 @@import hashlibimport jsonimport os+import shutilimport tempfilefrom django.core.management import call_command@@ -8,17 +9,19 @@ from django.test import TestCase, override_settingsfrom documents.management.commands import document_exporterfrom documents.models import Document, Tag, DocumentType, Correspondent+from documents.tests.utils import DirectoriesMixin-class TestExporter(TestCase):+class TestExporter(DirectoriesMixin, TestCase):@override_settings(- ORIGINALS_DIR=os.path.join(os.path.dirname(__file__), "samples", "originals"),- THUMBNAIL_DIR=os.path.join(os.path.dirname(__file__), "samples", "thumb"),PASSPHRASE="test")def test_exporter(self):- file = os.path.join(os.path.dirname(__file__), "samples", "originals", "0000001.pdf")+ shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))+ shutil.copytree(os.path.join(os.path.dirname(__file__), "samples", "documents"), os.path.join(self.dirs.media_dir, "documents"))++ file = os.path.join(self.dirs.originals_dir, "0000001.pdf")with open(file, "rb") as f:checksum = hashlib.md5(f.read()).hexdigest()