mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	added ASN to filename format #519
This commit is contained in:
		| @@ -217,6 +217,7 @@ will create a directory structure as follows: | ||||
|  | ||||
| Paperless provides the following placeholders withing filenames: | ||||
|  | ||||
| * ``{asn}``: The archive serial number of the document, or "none". | ||||
| * ``{correspondent}``: The name of the correspondent, or "none". | ||||
| * ``{document_type}``: The name of the document type, or "none". | ||||
| * ``{tag_list}``: A comma separated list of all tags assigned to the document. | ||||
|   | ||||
| @@ -131,6 +131,11 @@ def generate_filename(doc, counter=0, append_gpg=True, archive_filename=False): | ||||
|             else: | ||||
|                 document_type = "none" | ||||
|  | ||||
|             if doc.archive_serial_number: | ||||
|                 asn = str(doc.archive_serial_number) | ||||
|             else: | ||||
|                 asn = "none" | ||||
|  | ||||
|             path = settings.PAPERLESS_FILENAME_FORMAT.format( | ||||
|                 title=pathvalidate.sanitize_filename( | ||||
|                     doc.title, replacement_text="-"), | ||||
| @@ -144,6 +149,7 @@ def generate_filename(doc, counter=0, append_gpg=True, archive_filename=False): | ||||
|                 added_year=doc.added.year 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", | ||||
|                 asn=asn, | ||||
|                 tags=tags, | ||||
|                 tag_list=tag_list | ||||
|             ).strip() | ||||
|   | ||||
| @@ -201,6 +201,13 @@ class TestFileHandling(DirectoriesMixin, TestCase): | ||||
|  | ||||
|         self.assertEqual(generate_filename(d), "my_doc_type - the_doc.pdf") | ||||
|  | ||||
|     @override_settings(PAPERLESS_FILENAME_FORMAT="{asn} - {title}") | ||||
|     def test_asn(self): | ||||
|         d1 = Document.objects.create(title="the_doc", mime_type="application/pdf", archive_serial_number=652, checksum="A") | ||||
|         d2 = Document.objects.create(title="the_doc", mime_type="application/pdf", archive_serial_number=None, checksum="B") | ||||
|         self.assertEqual(generate_filename(d1), "652 - the_doc.pdf") | ||||
|         self.assertEqual(generate_filename(d2), "none - the_doc.pdf") | ||||
|  | ||||
|     @override_settings(PAPERLESS_FILENAME_FORMAT="{tags[type]}") | ||||
|     def test_tags_with_underscore(self): | ||||
|         document = Document() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler