Get rid of fill_list and rather use defaultdict

This commit is contained in:
Wolf-Bastian Poettner 2020-03-28 20:57:23 +00:00
parent 12c7b0d5f5
commit 7f1e1052fe
2 changed files with 10 additions and 20 deletions

View File

@ -328,25 +328,15 @@ class Document(models.Model):
if settings.PAPERLESS_FILENAME_FORMAT is not None: if settings.PAPERLESS_FILENAME_FORMAT is not None:
tag = defaultdict(lambda: slugify(None), tag = defaultdict(lambda: slugify(None),
self.many_to_dictionary(self.tags)) self.many_to_dictionary(self.tags))
list_length = 10 tags = defaultdict(lambda: slugify(None),
tags = self.many_to_list(self.tags) enumerate(self.many_to_list(self.tags)))
while True: path = settings.PAPERLESS_FILENAME_FORMAT.format(
tags = Document.fill_list(tags, list_length, None) correspondent=slugify(self.correspondent),
try: title=slugify(self.title),
path = settings.PAPERLESS_FILENAME_FORMAT.format( created=slugify(self.created),
correspondent=slugify(self.correspondent), added=slugify(self.added),
title=slugify(self.title), tag=tag,
created=slugify(self.created), tags=tags)
added=slugify(self.added),
tag=tag,
tags=tags)
break
except IndexError:
list_length *= 10
if list_length > 1000:
path = ""
break
else: else:
path = "" path = ""

View File

@ -264,7 +264,7 @@ class TestDate(TestCase):
# Ensure that filename is properly generated # Ensure that filename is properly generated
tmp = document.source_filename tmp = document.source_filename
self.assertEqual(document.generate_source_filename(), self.assertEqual(document.generate_source_filename(),
"0000001.pdf") "none-0000001.pdf")
document.create_source_directory() document.create_source_directory()
Path(document.source_path).touch() Path(document.source_path).touch()