mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	prevent usage of {tags} directly.
This commit is contained in:
		@@ -8,6 +8,12 @@ from django.conf import settings
 | 
			
		||||
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):
 | 
			
		||||
    os.makedirs(os.path.dirname(source_path), exist_ok=True)
 | 
			
		||||
 | 
			
		||||
@@ -90,8 +96,8 @@ def generate_filename(doc, counter=0):
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        if settings.PAPERLESS_FILENAME_FORMAT is not None:
 | 
			
		||||
            tags = defaultdict(lambda: slugify(None),
 | 
			
		||||
                               many_to_dictionary(doc.tags))
 | 
			
		||||
            tags = defaultdictNoStr(lambda: slugify(None),
 | 
			
		||||
                                    many_to_dictionary(doc.tags))
 | 
			
		||||
 | 
			
		||||
            if doc.correspondent:
 | 
			
		||||
                correspondent = pathvalidate.sanitize_filename(
 | 
			
		||||
 
 | 
			
		||||
@@ -267,6 +267,15 @@ class TestFileHandling(DirectoriesMixin, TestCase):
 | 
			
		||||
        self.assertEqual(generate_filename(document),
 | 
			
		||||
                         "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}")
 | 
			
		||||
    def test_tag_list(self):
 | 
			
		||||
        doc = Document.objects.create(title="doc1", mime_type="application/pdf")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user