From 7f1e1052fe5b5195894da968c2f816de65f5133b Mon Sep 17 00:00:00 2001 From: Wolf-Bastian Poettner Date: Sat, 28 Mar 2020 20:57:23 +0000 Subject: [PATCH] Get rid of fill_list and rather use defaultdict --- src/documents/models.py | 28 ++++++++--------------- src/documents/tests/test_file_handling.py | 2 +- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/documents/models.py b/src/documents/models.py index 4929ea459..39dcc4a37 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -328,25 +328,15 @@ class Document(models.Model): if settings.PAPERLESS_FILENAME_FORMAT is not None: tag = defaultdict(lambda: slugify(None), self.many_to_dictionary(self.tags)) - list_length = 10 - tags = self.many_to_list(self.tags) - while True: - tags = Document.fill_list(tags, list_length, None) - try: - path = settings.PAPERLESS_FILENAME_FORMAT.format( - correspondent=slugify(self.correspondent), - title=slugify(self.title), - created=slugify(self.created), - added=slugify(self.added), - tag=tag, - tags=tags) - break - except IndexError: - list_length *= 10 - - if list_length > 1000: - path = "" - break + tags = defaultdict(lambda: slugify(None), + enumerate(self.many_to_list(self.tags))) + path = settings.PAPERLESS_FILENAME_FORMAT.format( + correspondent=slugify(self.correspondent), + title=slugify(self.title), + created=slugify(self.created), + added=slugify(self.added), + tag=tag, + tags=tags) else: path = "" diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.py index 3065948ea..f6c8d0eba 100644 --- a/src/documents/tests/test_file_handling.py +++ b/src/documents/tests/test_file_handling.py @@ -264,7 +264,7 @@ class TestDate(TestCase): # Ensure that filename is properly generated tmp = document.source_filename self.assertEqual(document.generate_source_filename(), - "0000001.pdf") + "none-0000001.pdf") document.create_source_directory() Path(document.source_path).touch()