Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
fixes #117
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaswinkler committed Dec 14, 2020
1 parent 251fc58 commit bad7caa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/documents/file_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 22 additions & 0 deletions src/documents/tests/test_file_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,28 @@ def test_filename_relative(self):

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()
Expand Down

0 comments on commit bad7caa

Please sign in to comment.