A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Use constants for manifest
CkuTda71eab0ae2e
diff --git a/src/documents/management/commands/document_exporter.py b/src/documents/management/commands/document_exporter.pyindex 8203f930e..2a4e03ad7 100644--- a/src/documents/management/commands/document_exporter.py+++ b/src/documents/management/commands/document_exporter.py@@ -10,6 +10,7 @@ from documents.models import Document, Correspondent, Tagfrom paperless.db import GnuPGfrom ...mixins import Renderable+from documents.settings import EXPORTER_FILE_NAME, EXPORTER_THUMBNAIL_NAMEclass Command(Renderable, BaseCommand):@@ -63,8 +64,8 @@ class Command(Renderable, BaseCommand):target = os.path.join(self.target, document.file_name)thumbnail_target = target + "-tumbnail.png"- document_dict["__exported_file_name__"] = target- document_dict["__exported_thumbnail_name__"] = thumbnail_target+ document_dict[EXPORTER_FILE_NAME] = target+ document_dict[EXPORTER_THUMBNAIL_NAME] = thumbnail_targetprint("Exporting: {}".format(target))diff --git a/src/documents/management/commands/document_importer.py b/src/documents/management/commands/document_importer.pyindex be6fbc8bd..942f10c00 100644--- a/src/documents/management/commands/document_importer.py+++ b/src/documents/management/commands/document_importer.py@@ -10,6 +10,8 @@ from paperless.db import GnuPGfrom ...mixins import Renderable+from documents.settings import EXPORTER_FILE_NAME, EXPORTER_THUMBNAIL_NAME+class Command(Renderable, BaseCommand):@@ -70,13 +72,13 @@ class Command(Renderable, BaseCommand):if not record["model"] == "documents.document":continue- if "__exported_file_name__" not in record:+ if EXPORTER_FILE_NAME not in record:raise CommandError('The manifest file contains a record which does not ''refer to an actual document file.')- doc_file = record["__exported_file_name__"]+ doc_file = record[EXPORTER_FILE_NAME]if not os.path.exists(doc_file):raise CommandError('The manifest file refers to "{}" which does not '@@ -90,8 +92,8 @@ class Command(Renderable, BaseCommand):if not record["model"] == "documents.document":continue- doc_file = record["__exported_file_name__"]- thumb_file = record["__exported_thumbnail_name__"]+ doc_file = record[EXPORTER_FILE_NAME]+ thumb_file = record[EXPORTER_THUMBNAIL_NAME]document = Document.objects.get(pk=record["pk"])with open(doc_file, "rb") as unencrypted:with open(document.source_path, "wb") as encrypted:diff --git a/src/documents/settings.py b/src/documents/settings.pynew file mode 100644index 000000000..ca73dc298--- /dev/null+++ b/src/documents/settings.py@@ -0,0 +1,3 @@+# Defines the names of file/thumbnail for the manifest for exporting/importing commands+EXPORTER_FILE_NAME = "__exported_file_name__"+EXPORTER_THUMBNAIL_NAME = "__exported_thumbnail_name__"\ No newline at end of filediff --git a/src/documents/tests/test_importer.py b/src/documents/tests/test_importer.pyindex 8880aba66..0efddbd71 100644--- a/src/documents/tests/test_importer.py+++ b/src/documents/tests/test_importer.py@@ -3,6 +3,8 @@ from django.test import TestCasefrom ..management.commands.document_importer import Command+from documents.settings import EXPORTER_FILE_NAME+class TestImporter(TestCase):@@ -27,7 +29,7 @@ class TestImporter(TestCase):cmd.manifest = [{"model": "documents.document",- "__exported_file_name__": "noexist.pdf"+ EXPORTER_FILE_NAME: "noexist.pdf"}]# self.assertRaises(CommandError, cmd._check_manifest)with self.assertRaises(CommandError) as cm: