mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 18:22:40 -04:00 
			
		
		
		
	Use constants for manifest
This commit is contained in:
		
							parent
							
								
									2e0e6bb8d2
								
							
						
					
					
						commit
						da71eab0ae
					
				| @ -10,6 +10,7 @@ from documents.models import Document, Correspondent, Tag | ||||
| from paperless.db import GnuPG | ||||
| 
 | ||||
| from ...mixins import Renderable | ||||
| from documents.settings import EXPORTER_FILE_NAME, EXPORTER_THUMBNAIL_NAME | ||||
| 
 | ||||
| 
 | ||||
| class 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_target | ||||
| 
 | ||||
|             print("Exporting: {}".format(target)) | ||||
| 
 | ||||
|  | ||||
| @ -10,6 +10,8 @@ from paperless.db import GnuPG | ||||
| 
 | ||||
| from ...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: | ||||
|  | ||||
							
								
								
									
										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 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: | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user