mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Adds more options for the filename formatting
This commit is contained in:
		 Trenton Holmes
					Trenton Holmes
				
			
				
					committed by
					
						 Trenton H
						Trenton H
					
				
			
			
				
	
			
			
			 Trenton H
						Trenton H
					
				
			
						parent
						
							9acb00dcba
						
					
				
				
					commit
					4fcaa72886
				
			| @@ -258,12 +258,18 @@ Paperless provides the following placeholders within filenames: | ||||
| * ``{tag_list}``: A comma separated list of all tags assigned to the document. | ||||
| * ``{title}``: The title of the document. | ||||
| * ``{created}``: The full date (ISO format) the document was created. | ||||
| * ``{created_year}``: Year created only. | ||||
| * ``{created_year}``: Year created only, formatted as the year with century. | ||||
| * ``{created_year_short}``: Year created only, formatted as the year without century, zero padded. | ||||
| * ``{created_month}``: Month created only (number 01-12). | ||||
| * ``{created_month_name}``: Month created name, as per locale | ||||
| * ``{created_month_name_short}``: Month created abbreviated name, as per locale | ||||
| * ``{created_day}``: Day created only (number 01-31). | ||||
| * ``{added}``: The full date (ISO format) the document was added to paperless. | ||||
| * ``{added_year}``: Year added only. | ||||
| * ``{added_year_short}``: Year added only, formatted as the year without century, zero padded. | ||||
| * ``{added_month}``: Month added only (number 01-12). | ||||
| * ``{added_month_name}``: Month added name, as per locale | ||||
| * ``{added_month_name_short}``: Month added abbreviated name, as per locale | ||||
| * ``{added_day}``: Day added only (number 01-31). | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -181,13 +181,19 @@ def generate_filename(doc, counter=0, append_gpg=True, archive_filename=False): | ||||
|                 correspondent=correspondent, | ||||
|                 document_type=document_type, | ||||
|                 created=datetime.date.isoformat(local_created), | ||||
|                 created_year=local_created.year, | ||||
|                 created_month=f"{local_created.month:02}", | ||||
|                 created_day=f"{local_created.day:02}", | ||||
|                 created_year=local_created.strftime("%Y"), | ||||
|                 created_year_short=local_created.strftime("%y"), | ||||
|                 created_month=local_created.strftime("%m"), | ||||
|                 created_month_name=local_created.strftime("%B"), | ||||
|                 created_month_name_short=local_created.strftime("%b"), | ||||
|                 created_day=local_created.strftime("%d"), | ||||
|                 added=datetime.date.isoformat(local_added), | ||||
|                 added_year=local_added.year, | ||||
|                 added_month=f"{local_added.month:02}", | ||||
|                 added_day=f"{local_added.day:02}", | ||||
|                 added_year=local_added.strftime("%Y"), | ||||
|                 added_year_short=local_added.strftime("%y"), | ||||
|                 added_month=local_added.strftime("%m"), | ||||
|                 added_month_name=local_added.strftime("%B"), | ||||
|                 added_month_name_short=local_added.strftime("%b"), | ||||
|                 added_day=local_added.strftime("%d"), | ||||
|                 asn=asn, | ||||
|                 tags=tags, | ||||
|                 tag_list=tag_list, | ||||
|   | ||||
| @@ -1036,6 +1036,34 @@ class TestFilenameGeneration(TestCase): | ||||
|         self.assertEqual(generate_filename(doc_a), "0000002.pdf") | ||||
|         self.assertEqual(generate_filename(doc_b), "SomeImportantNone/2020-07-25.pdf") | ||||
|  | ||||
|     @override_settings( | ||||
|         FILENAME_FORMAT="{created_year_short}/{created_month_name_short}/{created_month_name}/{title}", | ||||
|     ) | ||||
|     def test_short_names_created(self): | ||||
|         doc = Document.objects.create( | ||||
|             title="The Title", | ||||
|             created=timezone.make_aware( | ||||
|                 datetime.datetime(1989, 12, 21, 7, 36, 51, 153), | ||||
|             ), | ||||
|             mime_type="application/pdf", | ||||
|             pk=2, | ||||
|             checksum="2", | ||||
|         ) | ||||
|         self.assertEqual(generate_filename(doc), "89/Dec/December/The Title.pdf") | ||||
|  | ||||
|     @override_settings( | ||||
|         FILENAME_FORMAT="{added_year_short}/{added_month_name}/{added_month_name_short}/{title}", | ||||
|     ) | ||||
|     def test_short_names_added(self): | ||||
|         doc = Document.objects.create( | ||||
|             title="The Title", | ||||
|             added=timezone.make_aware(datetime.datetime(1984, 8, 21, 7, 36, 51, 153)), | ||||
|             mime_type="application/pdf", | ||||
|             pk=2, | ||||
|             checksum="2", | ||||
|         ) | ||||
|         self.assertEqual(generate_filename(doc), "84/August/Aug/The Title.pdf") | ||||
|  | ||||
|  | ||||
| def run(): | ||||
|     doc = Document.objects.create( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user