mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Allow filename to use tags[KEY] and tags[INDEX]
This commit is contained in:
parent
845313db52
commit
07bb9aa723
@ -60,7 +60,7 @@ PAPERLESS_EMAIL_SECRET=""
|
|||||||
# * {title}
|
# * {title}
|
||||||
# * {created}
|
# * {created}
|
||||||
# * {added}
|
# * {added}
|
||||||
# * {tag[KEY]} If your tags conform to key_value or key-value
|
# * {tags[KEY]} If your tags conform to key_value or key-value
|
||||||
# * {tags[INDEX]} If your tags are strings, select the tag by index
|
# * {tags[INDEX]} If your tags are strings, select the tag by index
|
||||||
# Uniqueness of filenames is ensured, as an incrementing counter is attached
|
# Uniqueness of filenames is ensured, as an incrementing counter is attached
|
||||||
# to each filename.
|
# to each filename.
|
||||||
|
@ -289,7 +289,10 @@ class Document(models.Model):
|
|||||||
# entries contain an _ or - which will be used as a delimiter
|
# entries contain an _ or - which will be used as a delimiter
|
||||||
mydictionary = dict()
|
mydictionary = dict()
|
||||||
|
|
||||||
for t in field.all():
|
for index, t in enumerate(field.all()):
|
||||||
|
# Populate tag names by index
|
||||||
|
mydictionary[index] = slugify(t.name)
|
||||||
|
|
||||||
# Find delimiter
|
# Find delimiter
|
||||||
delimiter = t.name.find('_')
|
delimiter = t.name.find('_')
|
||||||
|
|
||||||
@ -306,16 +309,6 @@ class Document(models.Model):
|
|||||||
|
|
||||||
return mydictionary
|
return mydictionary
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def many_to_list(field):
|
|
||||||
# Converts ManyToManyField to list
|
|
||||||
mylist = list()
|
|
||||||
|
|
||||||
for t in field.all():
|
|
||||||
mylist.append(slugify(t.name))
|
|
||||||
|
|
||||||
return mylist
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fill_list(input_list, length, filler):
|
def fill_list(input_list, length, filler):
|
||||||
while len(input_list) < length:
|
while len(input_list) < length:
|
||||||
@ -326,16 +319,13 @@ class Document(models.Model):
|
|||||||
def generate_source_filename(self):
|
def generate_source_filename(self):
|
||||||
# Create filename based on configured format
|
# Create filename based on configured format
|
||||||
if settings.PAPERLESS_FILENAME_FORMAT is not None:
|
if settings.PAPERLESS_FILENAME_FORMAT is not None:
|
||||||
tag = defaultdict(lambda: slugify(None),
|
|
||||||
self.many_to_dictionary(self.tags))
|
|
||||||
tags = defaultdict(lambda: slugify(None),
|
tags = defaultdict(lambda: slugify(None),
|
||||||
enumerate(self.many_to_list(self.tags)))
|
self.many_to_dictionary(self.tags))
|
||||||
path = settings.PAPERLESS_FILENAME_FORMAT.format(
|
path = settings.PAPERLESS_FILENAME_FORMAT.format(
|
||||||
correspondent=slugify(self.correspondent),
|
correspondent=slugify(self.correspondent),
|
||||||
title=slugify(self.title),
|
title=slugify(self.title),
|
||||||
created=slugify(self.created),
|
created=slugify(self.created),
|
||||||
added=slugify(self.added),
|
added=slugify(self.added),
|
||||||
tag=tag,
|
|
||||||
tags=tags)
|
tags=tags)
|
||||||
else:
|
else:
|
||||||
path = ""
|
path = ""
|
||||||
|
@ -145,7 +145,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".
|
@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".
|
||||||
format(str(uuid4())[:8]))
|
format(str(uuid4())[:8]))
|
||||||
@override_settings(PAPERLESS_FILENAME_FORMAT="{tag[type]}")
|
@override_settings(PAPERLESS_FILENAME_FORMAT="{tags[type]}")
|
||||||
def test_tags_with_underscore(self):
|
def test_tags_with_underscore(self):
|
||||||
document = Document()
|
document = Document()
|
||||||
document.file_type = "pdf"
|
document.file_type = "pdf"
|
||||||
@ -168,7 +168,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".
|
@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".
|
||||||
format(str(uuid4())[:8]))
|
format(str(uuid4())[:8]))
|
||||||
@override_settings(PAPERLESS_FILENAME_FORMAT="{tag[type]}")
|
@override_settings(PAPERLESS_FILENAME_FORMAT="{tags[type]}")
|
||||||
def test_tags_with_dash(self):
|
def test_tags_with_dash(self):
|
||||||
document = Document()
|
document = Document()
|
||||||
document.file_type = "pdf"
|
document.file_type = "pdf"
|
||||||
@ -191,7 +191,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".
|
@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".
|
||||||
format(str(uuid4())[:8]))
|
format(str(uuid4())[:8]))
|
||||||
@override_settings(PAPERLESS_FILENAME_FORMAT="{tag[type]}")
|
@override_settings(PAPERLESS_FILENAME_FORMAT="{tags[type]}")
|
||||||
def test_tags_malformed(self):
|
def test_tags_malformed(self):
|
||||||
document = Document()
|
document = Document()
|
||||||
document.file_type = "pdf"
|
document.file_type = "pdf"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user