A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Adds more options for the filename formatting
Trenton Holmes4fcaa7288619
diff --git a/docs/advanced_usage.rst b/docs/advanced_usage.rstindex 844a73817..0dd7e9601 100644--- a/docs/advanced_usage.rst+++ b/docs/advanced_usage.rst@@ -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).diff --git a/src/documents/file_handling.py b/src/documents/file_handling.pyindex e3f13c077..2036cf443 100644--- a/src/documents/file_handling.py+++ b/src/documents/file_handling.py@@ -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,diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.pyindex 400c17413..8d726b339 100644--- a/src/documents/tests/test_file_handling.py+++ b/src/documents/tests/test_file_handling.py@@ -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(