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:
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 = ""

View File

@ -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()