mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-05-02 12:45:23 +00:00
Enhancement: add version label filename placeholder (#12185)
* Enhancement: add version label filename placeholder * fix test * add workflow placeholder * docs and missing version_label * typo * fix consume placeholder * update docs * Apply suggestion from @shamoon * fix None value --------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
@@ -428,7 +428,11 @@ class TestConsumer(
|
||||
DocumentMetadataOverrides(
|
||||
correspondent_id=c.pk,
|
||||
document_type_id=dt.pk,
|
||||
title="{{correspondent}}{{document_type}} {{added_month}}-{{added_year_short}}",
|
||||
title=(
|
||||
"{{correspondent}}{{document_type}} "
|
||||
"{{added_month}}-{{added_year_short}}.{{version_label}}"
|
||||
),
|
||||
version_label="v2",
|
||||
),
|
||||
) as consumer:
|
||||
consumer.run()
|
||||
@@ -436,7 +440,10 @@ class TestConsumer(
|
||||
document = Document.objects.first()
|
||||
|
||||
now = timezone.now()
|
||||
self.assertEqual(document.title, f"{c.name}{dt.name} {now.strftime('%m-%y')}")
|
||||
self.assertEqual(
|
||||
document.title,
|
||||
f"{c.name}{dt.name} {now.strftime('%m-%y')}.v2",
|
||||
)
|
||||
self._assert_first_last_send_progress()
|
||||
|
||||
def testOverrideOwner(self) -> None:
|
||||
|
||||
@@ -281,6 +281,32 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
self.assertEqual(generate_filename(d1), Path("652 - the_doc.pdf"))
|
||||
self.assertEqual(generate_filename(d2), Path("none - the_doc.pdf"))
|
||||
|
||||
@override_settings(FILENAME_FORMAT="{title}.{version_label}")
|
||||
def test_version_label(self) -> None:
|
||||
d1 = Document.objects.create(
|
||||
title="the_doc",
|
||||
mime_type="application/pdf",
|
||||
checksum="A",
|
||||
version_label="Version #2",
|
||||
)
|
||||
d2 = Document.objects.create(
|
||||
title="the_doc",
|
||||
mime_type="application/pdf",
|
||||
checksum="B",
|
||||
)
|
||||
d3 = Document.objects.create(
|
||||
title="the_doc",
|
||||
mime_type="application/pdf",
|
||||
checksum="C",
|
||||
version_label="Super weird %@\"'<> ¯\\_(ツ)_/¯",
|
||||
)
|
||||
self.assertEqual(generate_filename(d1), Path("the_doc.Version #2.pdf"))
|
||||
self.assertEqual(generate_filename(d2), Path("the_doc.none.pdf"))
|
||||
self.assertEqual(
|
||||
generate_filename(d3),
|
||||
Path("the_doc.Super weird %@-'-- ¯-_(ツ)_-¯.pdf"),
|
||||
)
|
||||
|
||||
@override_settings(FILENAME_FORMAT="{title} {tag_list}")
|
||||
def test_tag_list(self) -> None:
|
||||
doc = Document.objects.create(title="doc1", mime_type="application/pdf")
|
||||
|
||||
@@ -3412,7 +3412,10 @@ class TestWorkflows(
|
||||
)
|
||||
webhook_action = WorkflowActionWebhook.objects.create(
|
||||
use_params=False,
|
||||
body="Test message: {{doc_url}} with id {{doc_id}}",
|
||||
body=(
|
||||
"Test message: {{doc_url}} with id {{doc_id}} "
|
||||
"and version {{version_label}}"
|
||||
),
|
||||
url="http://paperless-ngx.com",
|
||||
include_document=False,
|
||||
)
|
||||
@@ -3436,6 +3439,7 @@ class TestWorkflows(
|
||||
title="sample test",
|
||||
correspondent=self.c,
|
||||
original_filename="sample.pdf",
|
||||
version_label="v3",
|
||||
)
|
||||
|
||||
run_workflows(WorkflowTrigger.WorkflowTriggerType.DOCUMENT_UPDATED, doc)
|
||||
@@ -3444,7 +3448,7 @@ class TestWorkflows(
|
||||
url="http://paperless-ngx.com",
|
||||
data=(
|
||||
f"Test message: http://localhost:8000/paperless/documents/{doc.id}/"
|
||||
f" with id {doc.id}"
|
||||
f" with id {doc.id} and version {doc.version_label}"
|
||||
),
|
||||
headers={},
|
||||
files=None,
|
||||
|
||||
Reference in New Issue
Block a user