A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Enhancement: include DOCUMENT_TYPE to post consume scripts (#9977)
matthesriekee9746aa0e318
diff --git a/docs/advanced_usage.md b/docs/advanced_usage.mdindex 87f397954..aa52d2f59 100644--- a/docs/advanced_usage.md+++ b/docs/advanced_usage.md@@ -179,6 +179,7 @@ variables:| ---------------------------- | ---------------------------------------------- || `DOCUMENT_ID` | Database primary key of the document || `DOCUMENT_FILE_NAME` | Formatted filename, not including paths |+| `DOCUMENT_TYPE` | The document type (if any) || `DOCUMENT_CREATED` | Date & time when document created || `DOCUMENT_MODIFIED` | Date & time when document was last modified || `DOCUMENT_ADDED` | Date & time when document was added |diff --git a/scripts/post-consumption-example.sh b/scripts/post-consumption-example.shindex 154f9df71..fbcd0b4cf 100755--- a/scripts/post-consumption-example.sh+++ b/scripts/post-consumption-example.sh@@ -6,6 +6,7 @@ A document with an id of ${DOCUMENT_ID} was just consumed. I know thefollowing additional information about it:* Generated File Name: ${DOCUMENT_FILE_NAME}+* Document type: ${DOCUMENT_TYPE}* Archive Path: ${DOCUMENT_ARCHIVE_PATH}* Source Path: ${DOCUMENT_SOURCE_PATH}* Created: ${DOCUMENT_CREATED}diff --git a/src/documents/consumer.py b/src/documents/consumer.pyindex c78c21d37..7a57d2535 100644--- a/src/documents/consumer.py+++ b/src/documents/consumer.py@@ -303,6 +303,7 @@ class ConsumerPlugin(script_env = os.environ.copy()script_env["DOCUMENT_ID"] = str(document.pk)+ script_env["DOCUMENT_TYPE"] = str(document.document_type)script_env["DOCUMENT_CREATED"] = str(document.created)script_env["DOCUMENT_MODIFIED"] = str(document.modified)script_env["DOCUMENT_ADDED"] = str(document.added)diff --git a/src/documents/tests/test_consumer.py b/src/documents/tests/test_consumer.pyindex 370ff0ef6..3c17ddfaf 100644--- a/src/documents/tests/test_consumer.py+++ b/src/documents/tests/test_consumer.py@@ -1174,12 +1174,16 @@ class PostConsumeTestCase(DirectoriesMixin, GetConsumerMixin, TestCase):m.assert_called_once()@mock.patch("documents.consumer.run_subprocess")- def test_post_consume_script_with_correspondent(self, m):+ def test_post_consume_script_with_correspondent_and_type(self, m):with tempfile.NamedTemporaryFile() as script:with override_settings(POST_CONSUME_SCRIPT=script.name):c = Correspondent.objects.create(name="my_bank")+ t = DocumentType.objects.create(+ name="Test type",+ )doc = Document.objects.create(title="Test",+ document_type=t,mime_type="application/pdf",correspondent=c,)@@ -1207,6 +1211,7 @@ class PostConsumeTestCase(DirectoriesMixin, GetConsumerMixin, TestCase):subset = {"DOCUMENT_ID": str(doc.pk),+ "DOCUMENT_TYPE": "Test type","DOCUMENT_DOWNLOAD_URL": f"/api/documents/{doc.pk}/download/","DOCUMENT_THUMBNAIL_URL": f"/api/documents/{doc.pk}/thumb/","DOCUMENT_CORRESPONDENT": "my_bank",