From 3fcbd8f3acd81d6298df3002132b260595508eb5 Mon Sep 17 00:00:00 2001 From: Gwyn Hannay Date: Sat, 18 Jun 2022 08:10:22 +0800 Subject: [PATCH 1/5] update files and model to include new field --- src-ui/src/app/data/paperless-document-metadata.ts | 2 ++ src/documents/admin.py | 1 + src/documents/consumer.py | 1 + src/documents/models.py | 10 ++++++++++ src/documents/views.py | 1 + 5 files changed, 15 insertions(+) diff --git a/src-ui/src/app/data/paperless-document-metadata.ts b/src-ui/src/app/data/paperless-document-metadata.ts index 1f9155b3a..152f69046 100644 --- a/src-ui/src/app/data/paperless-document-metadata.ts +++ b/src-ui/src/app/data/paperless-document-metadata.ts @@ -7,5 +7,7 @@ export interface PaperlessDocumentMetadata { media_filename?: string + original_filename?: string + has_archive_version?: boolean } diff --git a/src/documents/admin.py b/src/documents/admin.py index 3e3f1eb1c..6fa06c49b 100644 --- a/src/documents/admin.py +++ b/src/documents/admin.py @@ -42,6 +42,7 @@ class DocumentAdmin(admin.ModelAdmin): "checksum", "archive_filename", "archive_checksum", + "original_filename", ) list_display_links = ("title",) diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 69a9efb48..bbad88b12 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -475,6 +475,7 @@ class Consumer(LoggingMixin): created=create_date, modified=create_date, storage_type=storage_type, + original_filename=self.filename ) self.apply_overrides(document) diff --git a/src/documents/models.py b/src/documents/models.py index d8e02e570..af96104e0 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -214,6 +214,16 @@ class Document(models.Model): help_text=_("Current archive filename in storage"), ) + original_filename = models.FilePathField( + _("original filename"), + max_length=1024, + editable=False, + default=None, + unique=False, + null=True, + help_text=_("The original name of the file when it was uploaded") + ) + archive_serial_number = models.IntegerField( _("archive serial number"), blank=True, diff --git a/src/documents/views.py b/src/documents/views.py index 84fc38a38..b261f37fd 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -313,6 +313,7 @@ class DocumentViewSet( "original_metadata": self.get_metadata(doc.source_path, doc.mime_type), "archive_checksum": doc.archive_checksum, "archive_media_filename": doc.archive_filename, + "original_filename": doc.original_filename, } if doc.has_archive_version: From 4194b248b9439c8d7cd5de4d31cbb49cdf6b86df Mon Sep 17 00:00:00 2001 From: Gwyn Hannay Date: Mon, 25 Jul 2022 14:40:43 +0800 Subject: [PATCH 2/5] create migration for original filename --- .../1023_document_original_filename.py | 18 ++++++++++++++++++ src/documents/models.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/documents/migrations/1023_document_original_filename.py diff --git a/src/documents/migrations/1023_document_original_filename.py b/src/documents/migrations/1023_document_original_filename.py new file mode 100644 index 000000000..53e451dba --- /dev/null +++ b/src/documents/migrations/1023_document_original_filename.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.6 on 2022-07-25 06:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('documents', '1022_paperlesstask'), + ] + + operations = [ + migrations.AddField( + model_name='document', + name='original_filename', + field=models.CharField(default=None, editable=False, help_text='The original name of the file when it was uploaded', max_length=1024, null=True, verbose_name='original filename'), + ), + ] diff --git a/src/documents/models.py b/src/documents/models.py index af96104e0..c371bc99e 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -214,7 +214,7 @@ class Document(models.Model): help_text=_("Current archive filename in storage"), ) - original_filename = models.FilePathField( + original_filename = models.CharField( _("original filename"), max_length=1024, editable=False, From e3cc5c301386d257657de5559813d46046b14eda Mon Sep 17 00:00:00 2001 From: Gwyn Hannay Date: Fri, 29 Jul 2022 20:32:07 -0700 Subject: [PATCH 3/5] format code --- src/documents/consumer.py | 2 +- .../migrations/1023_document_original_filename.py | 15 +++++++++++---- src/documents/models.py | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/documents/consumer.py b/src/documents/consumer.py index bbad88b12..9cc9b758d 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -475,7 +475,7 @@ class Consumer(LoggingMixin): created=create_date, modified=create_date, storage_type=storage_type, - original_filename=self.filename + original_filename=self.filename, ) self.apply_overrides(document) diff --git a/src/documents/migrations/1023_document_original_filename.py b/src/documents/migrations/1023_document_original_filename.py index 53e451dba..065956bd9 100644 --- a/src/documents/migrations/1023_document_original_filename.py +++ b/src/documents/migrations/1023_document_original_filename.py @@ -6,13 +6,20 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('documents', '1022_paperlesstask'), + ("documents", "1022_paperlesstask"), ] operations = [ migrations.AddField( - model_name='document', - name='original_filename', - field=models.CharField(default=None, editable=False, help_text='The original name of the file when it was uploaded', max_length=1024, null=True, verbose_name='original filename'), + model_name="document", + name="original_filename", + field=models.CharField( + default=None, + editable=False, + help_text="The original name of the file when it was uploaded", + max_length=1024, + null=True, + verbose_name="original filename", + ), ), ] diff --git a/src/documents/models.py b/src/documents/models.py index c371bc99e..f6df273ad 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -221,7 +221,7 @@ class Document(models.Model): default=None, unique=False, null=True, - help_text=_("The original name of the file when it was uploaded") + help_text=_("The original name of the file when it was uploaded"), ) archive_serial_number = models.IntegerField( From baeb2a074ad8b309db4ca6a5669d0a2c3b40193b Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 21 Aug 2022 08:06:56 -0700 Subject: [PATCH 4/5] Add original filename to frontend doc detail metadata --- src-ui/messages.xlf | 31 ++++++++++++------- .../document-detail.component.html | 4 +++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index c79413a4b..b17b0ee10 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -816,7 +816,7 @@ src/app/components/document-detail/document-detail.component.html - 174 + 178 src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html @@ -1570,78 +1570,85 @@ 113 + + Original filename + + src/app/components/document-detail/document-detail.component.html + 117 + + Original MD5 checksum src/app/components/document-detail/document-detail.component.html - 117 + 121 Original file size src/app/components/document-detail/document-detail.component.html - 121 + 125 Original mime type src/app/components/document-detail/document-detail.component.html - 125 + 129 Archive MD5 checksum src/app/components/document-detail/document-detail.component.html - 129 + 133 Archive file size src/app/components/document-detail/document-detail.component.html - 133 + 137 Original document metadata src/app/components/document-detail/document-detail.component.html - 139 + 143 Archived document metadata src/app/components/document-detail/document-detail.component.html - 140 + 144 Enter Password src/app/components/document-detail/document-detail.component.html - 162 + 166 src/app/components/document-detail/document-detail.component.html - 192 + 196 Discard src/app/components/document-detail/document-detail.component.html - 172 + 176 Save & next src/app/components/document-detail/document-detail.component.html - 173 + 177 diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index 6c8fc463f..764a587e0 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -113,6 +113,10 @@ Media filename {{metadata?.media_filename}} + + Original filename + {{metadata?.original_filename}} + Original MD5 checksum {{metadata?.original_checksum}} From 9b24cf7591507ec8def0ff3f37d334c0bd38b07e Mon Sep 17 00:00:00 2001 From: Trenton Holmes Date: Sun, 21 Aug 2022 16:16:28 -0700 Subject: [PATCH 5/5] Also provide the original file name to the post consumption script --- docs/advanced_usage.rst | 1 + src/documents/consumer.py | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/advanced_usage.rst b/docs/advanced_usage.rst index ba5b3cbaa..7709da1c9 100644 --- a/docs/advanced_usage.rst +++ b/docs/advanced_usage.rst @@ -171,6 +171,7 @@ into paperless. It receives the following environment variables: * ``DOCUMENT_THUMBNAIL_URL`` * ``DOCUMENT_CORRESPONDENT`` * ``DOCUMENT_TAGS`` +* ``DOCUMENT_ORIGINAL_FILENAME`` The script can be in any language, but for a simple shell script example, you can take a look at `post-consumption-example.sh`_ in this project. diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 9cc9b758d..d1b01290a 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -203,6 +203,7 @@ class Consumer(LoggingMixin): script_env["DOCUMENT_TAGS"] = str( ",".join(document.tags.all().values_list("name", flat=True)), ) + script_env["DOCUMENT_ORIGINAL_FILENAME"] = str(document.original_filename) try: Popen(