mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	fixes #117
This commit is contained in:
		@@ -114,12 +114,12 @@ def generate_filename(doc, counter=0):
 | 
			
		||||
                document_type=document_type,
 | 
			
		||||
                created=datetime.date.isoformat(doc.created),
 | 
			
		||||
                created_year=doc.created.year if doc.created else "none",
 | 
			
		||||
                created_month=doc.created.month if doc.created else "none",
 | 
			
		||||
                created_day=doc.created.day if doc.created else "none",
 | 
			
		||||
                created_month=f"{doc.created.month:02}" if doc.created else "none",  # NOQA: E501
 | 
			
		||||
                created_day=f"{doc.created.day:02}" if doc.created else "none",
 | 
			
		||||
                added=datetime.date.isoformat(doc.added),
 | 
			
		||||
                added_year=doc.added.year if doc.added else "none",
 | 
			
		||||
                added_month=doc.added.month if doc.added else "none",
 | 
			
		||||
                added_day=doc.added.day if doc.added else "none",
 | 
			
		||||
                added_month=f"{doc.added.month:02}" if doc.added else "none",
 | 
			
		||||
                added_day=f"{doc.added.day:02}" if doc.added else "none",
 | 
			
		||||
                tags=tags,
 | 
			
		||||
                tag_list=",".join([tag.name for tag in doc.tags.all()])
 | 
			
		||||
            ).strip()
 | 
			
		||||
 
 | 
			
		||||
@@ -287,6 +287,28 @@ class TestFileHandling(DirectoriesMixin, TestCase):
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(doc.source_path, os.path.join(settings.ORIGINALS_DIR, "etc", "something", "doc1.pdf"))
 | 
			
		||||
 | 
			
		||||
    @override_settings(PAPERLESS_FILENAME_FORMAT="{created_year}-{created_month}-{created_day}")
 | 
			
		||||
    def test_created_year_month_day(self):
 | 
			
		||||
        d1 = datetime.datetime(2020, 3, 6, 1, 1, 1)
 | 
			
		||||
        doc1 = Document.objects.create(title="doc1", mime_type="application/pdf", created=d1)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(generate_filename(doc1), "2020-03-06.pdf")
 | 
			
		||||
 | 
			
		||||
        doc1.created = datetime.datetime(2020, 11, 16, 1, 1, 1)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(generate_filename(doc1), "2020-11-16.pdf")
 | 
			
		||||
 | 
			
		||||
    @override_settings(PAPERLESS_FILENAME_FORMAT="{added_year}-{added_month}-{added_day}")
 | 
			
		||||
    def test_added_year_month_day(self):
 | 
			
		||||
        d1 = datetime.datetime(232, 1, 9, 1, 1, 1)
 | 
			
		||||
        doc1 = Document.objects.create(title="doc1", mime_type="application/pdf", added=d1)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(generate_filename(doc1), "232-01-09.pdf")
 | 
			
		||||
 | 
			
		||||
        doc1.added = datetime.datetime(2020, 11, 16, 1, 1, 1)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(generate_filename(doc1), "2020-11-16.pdf")
 | 
			
		||||
 | 
			
		||||
    @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}/{correspondent}/{correspondent}")
 | 
			
		||||
    def test_nested_directory_cleanup(self):
 | 
			
		||||
        document = Document()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user