mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-31 02:27:10 -04:00 
			
		
		
		
	prevent usage of {tags} directly.
This commit is contained in:
		
							parent
							
								
									bad7caa8b9
								
							
						
					
					
						commit
						8cc0336338
					
				| @ -8,6 +8,12 @@ from django.conf import settings | |||||||
| from django.template.defaultfilters import slugify | from django.template.defaultfilters import slugify | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class defaultdictNoStr(defaultdict): | ||||||
|  | 
 | ||||||
|  |     def __str__(self): | ||||||
|  |         raise ValueError("Don't use {tags} directly.") | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def create_source_path_directory(source_path): | def create_source_path_directory(source_path): | ||||||
|     os.makedirs(os.path.dirname(source_path), exist_ok=True) |     os.makedirs(os.path.dirname(source_path), exist_ok=True) | ||||||
| 
 | 
 | ||||||
| @ -90,7 +96,7 @@ def generate_filename(doc, counter=0): | |||||||
| 
 | 
 | ||||||
|     try: |     try: | ||||||
|         if settings.PAPERLESS_FILENAME_FORMAT is not None: |         if settings.PAPERLESS_FILENAME_FORMAT is not None: | ||||||
|             tags = defaultdict(lambda: slugify(None), |             tags = defaultdictNoStr(lambda: slugify(None), | ||||||
|                                     many_to_dictionary(doc.tags)) |                                     many_to_dictionary(doc.tags)) | ||||||
| 
 | 
 | ||||||
|             if doc.correspondent: |             if doc.correspondent: | ||||||
|  | |||||||
| @ -267,6 +267,15 @@ class TestFileHandling(DirectoriesMixin, TestCase): | |||||||
|         self.assertEqual(generate_filename(document), |         self.assertEqual(generate_filename(document), | ||||||
|                          "none.pdf") |                          "none.pdf") | ||||||
| 
 | 
 | ||||||
|  |     @override_settings(PAPERLESS_FILENAME_FORMAT="{tags}") | ||||||
|  |     def test_tags_without_args(self): | ||||||
|  |         document = Document() | ||||||
|  |         document.mime_type = "application/pdf" | ||||||
|  |         document.storage_type = Document.STORAGE_TYPE_UNENCRYPTED | ||||||
|  |         document.save() | ||||||
|  | 
 | ||||||
|  |         self.assertEqual(generate_filename(document), f"{document.pk:07}.pdf") | ||||||
|  | 
 | ||||||
|     @override_settings(PAPERLESS_FILENAME_FORMAT="{title} {tag_list}") |     @override_settings(PAPERLESS_FILENAME_FORMAT="{title} {tag_list}") | ||||||
|     def test_tag_list(self): |     def test_tag_list(self): | ||||||
|         doc = Document.objects.create(title="doc1", mime_type="application/pdf") |         doc = Document.objects.create(title="doc1", mime_type="application/pdf") | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user