mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Unified PAPERLESS_DIRECTORY_FORMAT and PAPERLESS_FILENAME_FORMAT into
one configuration setting
This commit is contained in:
parent
86a51c6fa5
commit
6a671ebd22
@ -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=""
|
||||
|
||||
###############################################################################
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user