A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Allow filename to use tags[KEY] and tags[INDEX]
Wolf-Bastian Poettner07bb9aa72327
diff --git a/paperless.conf.example b/paperless.conf.exampleindex a375ae8ba..b99995b8f 100644--- a/paperless.conf.example+++ b/paperless.conf.example@@ -60,7 +60,7 @@ PAPERLESS_EMAIL_SECRET=""# * {title}# * {created}# * {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# Uniqueness of filenames is ensured, as an incrementing counter is attached# to each filename.diff --git a/src/documents/models.py b/src/documents/models.pyindex 17357c1a7..006c214fa 100644--- a/src/documents/models.py+++ b/src/documents/models.py@@ -289,7 +289,10 @@ class Document(models.Model):# entries contain an _ or - which will be used as a delimitermydictionary = dict()- for t in field.all():+ for index, t in enumerate(field.all()):+ # Populate tag names by index+ mydictionary[index] = slugify(t.name)+# Find delimiterdelimiter = t.name.find('_')@@ -306,16 +309,6 @@ class Document(models.Model):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-@staticmethoddef fill_list(input_list, length, filler):while len(input_list) < length:@@ -326,16 +319,13 @@ class Document(models.Model):def generate_source_filename(self):# Create filename based on configured formatif settings.PAPERLESS_FILENAME_FORMAT is not None:- tag = defaultdict(lambda: slugify(None),- self.many_to_dictionary(self.tags))tags = defaultdict(lambda: slugify(None),- enumerate(self.many_to_list(self.tags)))+ 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),- tag=tag,tags=tags)else:path = ""diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.pyindex fae1c0634..7af99adfc 100644--- a/src/documents/tests/test_file_handling.py+++ b/src/documents/tests/test_file_handling.py@@ -145,7 +145,7 @@ class TestDate(TestCase):@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".format(str(uuid4())[:8]))- @override_settings(PAPERLESS_FILENAME_FORMAT="{tag[type]}")+ @override_settings(PAPERLESS_FILENAME_FORMAT="{tags[type]}")def test_tags_with_underscore(self):document = Document()document.file_type = "pdf"@@ -168,7 +168,7 @@ class TestDate(TestCase):@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".format(str(uuid4())[:8]))- @override_settings(PAPERLESS_FILENAME_FORMAT="{tag[type]}")+ @override_settings(PAPERLESS_FILENAME_FORMAT="{tags[type]}")def test_tags_with_dash(self):document = Document()document.file_type = "pdf"@@ -191,7 +191,7 @@ class TestDate(TestCase):@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".format(str(uuid4())[:8]))- @override_settings(PAPERLESS_FILENAME_FORMAT="{tag[type]}")+ @override_settings(PAPERLESS_FILENAME_FORMAT="{tags[type]}")def test_tags_malformed(self):document = Document()document.file_type = "pdf"