diff --git a/paperless.conf.example b/paperless.conf.example index 8f586e601..ff96bfe20 100644 --- a/paperless.conf.example +++ b/paperless.conf.example @@ -54,7 +54,7 @@ PAPERLESS_CONSUME_MAIL_PASS="" # ignored. PAPERLESS_EMAIL_SECRET="" -# Specify a filename format for an (optional) subdirectory and the document itself +# Specify a filename format for the document (directories are supported) # Use the following placeholders: # * {correspondent} # * {title} @@ -63,7 +63,6 @@ PAPERLESS_EMAIL_SECRET="" # * {tags[FILTER]} # Uniqueness of filenames is ensured, as an incrementing counter is attached # to each filename. -#PAPERLESS_DIRECTORY_FORMAT="" #PAPERLESS_FILENAME_FORMAT="" ############################################################################### diff --git a/src/documents/models.py b/src/documents/models.py index 58206ba11..25caddebf 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -299,31 +299,17 @@ class Document(models.Model): return mydictionary def generate_source_filename(self): - # Create directory name based on configured format - if settings.PAPERLESS_DIRECTORY_FORMAT is not None: - directory = settings.PAPERLESS_DIRECTORY_FORMAT.format( - correspondent=slugify(self.correspondent), - title=slugify(self.title), - created=slugify(self.created), - added=slugify(self.added), - tags=defaultdict(str, - self.many_to_dictionary(self.tags))) - else: - directory = "" - # Create filename based on configured format if settings.PAPERLESS_FILENAME_FORMAT is not None: - filename = settings.PAPERLESS_FILENAME_FORMAT.format( - correspondent=slugify(self.correspondent), - title=slugify(self.title), - created=slugify(self.created), - added=slugify(self.added), - tags=defaultdict(str, - self.many_to_dictionary(self.tags))) + path = settings.PAPERLESS_FILENAME_FORMAT.format( + correspondent=slugify(self.correspondent), + title=slugify(self.title), + created=slugify(self.created), + added=slugify(self.added), + tags=defaultdict(str, + self.many_to_dictionary(self.tags))) else: - filename = "" - - path = os.path.join(directory, filename) + path = "" # Always append the primary key to guarantee uniqueness of filename if len(path) > 0: diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.py index 46f5bbc9d..30dc8fd81 100644 --- a/src/documents/tests/test_file_handling.py +++ b/src/documents/tests/test_file_handling.py @@ -14,7 +14,6 @@ from django.conf import settings class TestDate(TestCase): - @override_settings(PAPERLESS_DIRECTORY_FORMAT="") @override_settings(PAPERLESS_FILENAME_FORMAT="") def test_source_filename(self): document = Document() @@ -27,7 +26,6 @@ class TestDate(TestCase): document.filename = "test.pdf" self.assertEqual(document.source_filename, "test.pdf") - @override_settings(PAPERLESS_DIRECTORY_FORMAT="") @override_settings(PAPERLESS_FILENAME_FORMAT="") def test_generate_source_filename(self): document = Document() @@ -43,8 +41,7 @@ class TestDate(TestCase): @override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}". format(str(uuid4())[:8])) - @override_settings(PAPERLESS_DIRECTORY_FORMAT="{correspondent}") - @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}") + @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}/{correspondent}") def test_file_renaming(self): document = Document() document.file_type = "pdf" @@ -89,8 +86,7 @@ class TestDate(TestCase): @override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}". format(str(uuid4())[:8])) - @override_settings(PAPERLESS_DIRECTORY_FORMAT="{correspondent}") - @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}") + @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}/{correspondent}") def test_document_delete(self): document = Document() document.file_type = "pdf" @@ -113,8 +109,7 @@ class TestDate(TestCase): @override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}". format(str(uuid4())[:8])) - @override_settings(PAPERLESS_DIRECTORY_FORMAT="{correspondent}") - @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}") + @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}/{correspondent}") def test_directory_not_empty(self): document = Document() document.file_type = "pdf" @@ -148,8 +143,7 @@ class TestDate(TestCase): @override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}". format(str(uuid4())[:8])) - @override_settings(PAPERLESS_DIRECTORY_FORMAT="{correspondent}/{correspondent}") - @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}") + @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}/{correspondent}/{correspondent}") def test_nested_directory_cleanup(self): document = Document() document.file_type = "pdf" @@ -178,7 +172,6 @@ class TestDate(TestCase): @override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}". format(str(uuid4())[:8])) - @override_settings(PAPERLESS_DIRECTORY_FORMAT=None) @override_settings(PAPERLESS_FILENAME_FORMAT=None) def test_format_none(self): document = Document() diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 4a7317e02..3cadc7d2b 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -336,5 +336,4 @@ PAPERLESS_RECENT_CORRESPONDENT_YEARS = int(os.getenv( "PAPERLESS_RECENT_CORRESPONDENT_YEARS", 0)) # Specify the filename format for out files -PAPERLESS_DIRECTORY_FORMAT = os.getenv("PAPERLESS_DIRECTORY_FORMAT") PAPERLESS_FILENAME_FORMAT = os.getenv("PAPERLESS_FILENAME_FORMAT")