mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Use constants for manifest
This commit is contained in:
		| @@ -10,6 +10,7 @@ from documents.models import Document, Correspondent, Tag | |||||||
| from paperless.db import GnuPG | from paperless.db import GnuPG | ||||||
|  |  | ||||||
| from ...mixins import Renderable | from ...mixins import Renderable | ||||||
|  | from documents.settings import EXPORTER_FILE_NAME, EXPORTER_THUMBNAIL_NAME | ||||||
|  |  | ||||||
|  |  | ||||||
| class Command(Renderable, BaseCommand): | class Command(Renderable, BaseCommand): | ||||||
| @@ -63,8 +64,8 @@ class Command(Renderable, BaseCommand): | |||||||
|  |  | ||||||
|             target = os.path.join(self.target, document.file_name) |             target = os.path.join(self.target, document.file_name) | ||||||
|             thumbnail_target = target + "-tumbnail.png" |             thumbnail_target = target + "-tumbnail.png" | ||||||
|             document_dict["__exported_file_name__"] = target |             document_dict[EXPORTER_FILE_NAME] = target | ||||||
|             document_dict["__exported_thumbnail_name__"] = thumbnail_target |             document_dict[EXPORTER_THUMBNAIL_NAME] = thumbnail_target | ||||||
|  |  | ||||||
|             print("Exporting: {}".format(target)) |             print("Exporting: {}".format(target)) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -10,6 +10,8 @@ from paperless.db import GnuPG | |||||||
|  |  | ||||||
| from ...mixins import Renderable | from ...mixins import Renderable | ||||||
|  |  | ||||||
|  | from documents.settings import EXPORTER_FILE_NAME, EXPORTER_THUMBNAIL_NAME | ||||||
|  |  | ||||||
|  |  | ||||||
| class Command(Renderable, BaseCommand): | class Command(Renderable, BaseCommand): | ||||||
|  |  | ||||||
| @@ -70,13 +72,13 @@ class Command(Renderable, BaseCommand): | |||||||
|             if not record["model"] == "documents.document": |             if not record["model"] == "documents.document": | ||||||
|                 continue |                 continue | ||||||
|  |  | ||||||
|             if "__exported_file_name__" not in record: |             if EXPORTER_FILE_NAME not in record: | ||||||
|                 raise CommandError( |                 raise CommandError( | ||||||
|                     'The manifest file contains a record which does not ' |                     'The manifest file contains a record which does not ' | ||||||
|                     'refer to an actual document file.' |                     '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): |             if not os.path.exists(doc_file): | ||||||
|                 raise CommandError( |                 raise CommandError( | ||||||
|                     'The manifest file refers to "{}" which does not ' |                     'The manifest file refers to "{}" which does not ' | ||||||
| @@ -90,8 +92,8 @@ class Command(Renderable, BaseCommand): | |||||||
|             if not record["model"] == "documents.document": |             if not record["model"] == "documents.document": | ||||||
|                 continue |                 continue | ||||||
|  |  | ||||||
|             doc_file = record["__exported_file_name__"] |             doc_file = record[EXPORTER_FILE_NAME] | ||||||
|             thumb_file = record["__exported_thumbnail_name__"] |             thumb_file = record[EXPORTER_THUMBNAIL_NAME] | ||||||
|             document = Document.objects.get(pk=record["pk"]) |             document = Document.objects.get(pk=record["pk"]) | ||||||
|             with open(doc_file, "rb") as unencrypted: |             with open(doc_file, "rb") as unencrypted: | ||||||
|                 with open(document.source_path, "wb") as encrypted: |                 with open(document.source_path, "wb") as encrypted: | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								src/documents/settings.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/documents/settings.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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__" | ||||||
| @@ -3,6 +3,8 @@ from django.test import TestCase | |||||||
|  |  | ||||||
| from ..management.commands.document_importer import Command | from ..management.commands.document_importer import Command | ||||||
|  |  | ||||||
|  | from documents.settings import EXPORTER_FILE_NAME | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestImporter(TestCase): | class TestImporter(TestCase): | ||||||
|  |  | ||||||
| @@ -27,7 +29,7 @@ class TestImporter(TestCase): | |||||||
|  |  | ||||||
|         cmd.manifest = [{ |         cmd.manifest = [{ | ||||||
|             "model": "documents.document", |             "model": "documents.document", | ||||||
|             "__exported_file_name__": "noexist.pdf" |             EXPORTER_FILE_NAME: "noexist.pdf" | ||||||
|         }] |         }] | ||||||
|         # self.assertRaises(CommandError, cmd._check_manifest) |         # self.assertRaises(CommandError, cmd._check_manifest) | ||||||
|         with self.assertRaises(CommandError) as cm: |         with self.assertRaises(CommandError) as cm: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 CkuT
					CkuT