A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
localization for websockets
jonaswinkler2faa425caf1f
diff --git a/src-ui/messages.xlf b/src-ui/messages.xlfindex 93f970d86..eab8ed80e 100644--- a/src-ui/messages.xlf+++ b/src-ui/messages.xlf@@ -1617,6 +1617,97 @@<context context-type="linenumber">85</context></context-group></trans-unit>+ <trans-unit id="2119857572761283468" datatype="html">+ <source>Document already exists.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">14</context>+ </context-group>+ </trans-unit>+ <trans-unit id="148389968432135849" datatype="html">+ <source>File not found.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">15</context>+ </context-group>+ </trans-unit>+ <trans-unit id="1520671543092565667" datatype="html">+ <source>Pre-consume script does not exist.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">16</context>+ </context-group>+ </trans-unit>+ <trans-unit id="7742915911032564889" datatype="html">+ <source>Error while executing pre-consume script.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">17</context>+ </context-group>+ </trans-unit>+ <trans-unit id="8995193730018060346" datatype="html">+ <source>Post-consume script does not exist.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">18</context>+ </context-group>+ </trans-unit>+ <trans-unit id="256773668518189604" datatype="html">+ <source>Error while executing post-consume script.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">19</context>+ </context-group>+ </trans-unit>+ <trans-unit id="6252258095055634191" datatype="html">+ <source>Received new file.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">20</context>+ </context-group>+ </trans-unit>+ <trans-unit id="7337565919209746135" datatype="html">+ <source>File type not supported.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">21</context>+ </context-group>+ </trans-unit>+ <trans-unit id="5002399167376099234" datatype="html">+ <source>Processing document...</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">22</context>+ </context-group>+ </trans-unit>+ <trans-unit id="1085975194762600381" datatype="html">+ <source>Generating thumbnail...</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">23</context>+ </context-group>+ </trans-unit>+ <trans-unit id="3280851677698431426" datatype="html">+ <source>Retrieving date from document...</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">24</context>+ </context-group>+ </trans-unit>+ <trans-unit id="7162102384876037296" datatype="html">+ <source>Saving document...</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">25</context>+ </context-group>+ </trans-unit>+ <trans-unit id="4550450765009165976" datatype="html">+ <source>Finished.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/services/consumer-status.service.ts</context>+ <context context-type="linenumber">26</context>+ </context-group>+ </trans-unit><trans-unit id="1519954996184640001" datatype="html"><source>Error</source><context-group purpose="location">diff --git a/src-ui/src/app/services/consumer-status.service.ts b/src-ui/src/app/services/consumer-status.service.tsindex 8151b1c18..026c3c64f 100644--- a/src-ui/src/app/services/consumer-status.service.ts+++ b/src-ui/src/app/services/consumer-status.service.ts@@ -10,6 +10,22 @@ export enum FileStatusPhase {FAILED = 4}+export const FILE_STATUS_MESSAGES = {+ "document_already_exists": $localize`Document already exists.`,+ "file_not_found": $localize`File not found.`,+ "pre_consume_script_not_found": $localize`Pre-consume script does not exist.`,+ "pre_consume_script_error": $localize`Error while executing pre-consume script.`,+ "post_consume_script_not_found": $localize`Post-consume script does not exist.`,+ "post_consume_script_error": $localize`Error while executing post-consume script.`,+ "new_file": $localize`Received new file.`,+ "unsupported_type": $localize`File type not supported.`,+ "parsing_document": $localize`Processing document...`,+ "generating_thumbnail": $localize`Generating thumbnail...`,+ "parse_date": $localize`Retrieving date from document...`,+ "save_document": $localize`Saving document...`,+ "finished": $localize`Finished.`+}+export class FileStatus {filename: string@@ -116,7 +132,11 @@ export class ConsumerStatusService {let created = statusMessageGet.createdstatus.updateProgress(FileStatusPhase.PROCESSING, statusMessage.current_progress, statusMessage.max_progress)- status.message = statusMessage.message+ if (statusMessage.message && statusMessage.message in FILE_STATUS_MESSAGES) {+ status.message = FILE_STATUS_MESSAGES[statusMessage.message]+ } else if (statusMessage.message) {+ status.message = statusMessage.message+ }status.documentId = statusMessage.document_idif (created && statusMessage.status == 'STARTING') {diff --git a/src/documents/consumer.py b/src/documents/consumer.pyindex 05043201b..146b11014 100755--- a/src/documents/consumer.py+++ b/src/documents/consumer.py@@ -25,17 +25,30 @@ from .signals import (document_consumption_started)-from django.utils.translation import gettext as _-class ConsumerError(Exception):pass+MESSAGE_DOCUMENT_ALREADY_EXISTS = "document_already_exists"+MESSAGE_FILE_NOT_FOUND = "file_not_found"+MESSAGE_PRE_CONSUME_SCRIPT_NOT_FOUND = "pre_consume_script_not_found"+MESSAGE_PRE_CONSUME_SCRIPT_ERROR = "pre_consume_script_error"+MESSAGE_POST_CONSUME_SCRIPT_NOT_FOUND = "post_consume_script_not_found"+MESSAGE_POST_CONSUME_SCRIPT_ERROR = "post_consume_script_error"+MESSAGE_NEW_FILE = "new_file"+MESSAGE_UNSUPPORTED_TYPE = "unsupported_type"+MESSAGE_PARSING_DOCUMENT = "parsing_document"+MESSAGE_GENERATING_THUMBNAIL = "generating_thumbnail"+MESSAGE_PARSE_DATE = "parse_date"+MESSAGE_SAVE_DOCUMENT = "save_document"+MESSAGE_FINISHED = "finished"++class Consumer(LoggingMixin):def _send_progress(self, current_progress, max_progress, status,- message, document_id=None):+ message=None, document_id=None):payload = {'filename': os.path.basename(self.filename) if self.filename else None, # NOQA: E501'task_id': self.task_id,@@ -69,7 +82,7 @@ class Consumer(LoggingMixin):def pre_check_file_exists(self):if not os.path.isfile(self.path):self._fail(- _("File not found"),+ MESSAGE_FILE_NOT_FOUND,f"Cannot consume {self.path}: File not found.")@@ -80,7 +93,7 @@ class Consumer(LoggingMixin):if settings.CONSUMER_DELETE_DUPLICATES:os.unlink(self.path)self._fail(- _("Document already exists"),+ MESSAGE_DOCUMENT_ALREADY_EXISTS,f"Not consuming {self.filename}: It is a duplicate.")@@ -96,7 +109,7 @@ class Consumer(LoggingMixin):if not os.path.isfile(settings.PRE_CONSUME_SCRIPT):self._fail(- _("Pre-consume script does not exist."),+ MESSAGE_PRE_CONSUME_SCRIPT_NOT_FOUND,f"Configured pre-consume script "f"{settings.PRE_CONSUME_SCRIPT} does not exist.")@@ -104,7 +117,7 @@ class Consumer(LoggingMixin):Popen((settings.PRE_CONSUME_SCRIPT, self.path)).wait()except Exception as e:self._fail(- _("Error while executing pre-consume script"),+ MESSAGE_PRE_CONSUME_SCRIPT_ERROR,f"Error while executing pre-consume script: {e}")@@ -114,7 +127,7 @@ class Consumer(LoggingMixin):if not os.path.isfile(settings.POST_CONSUME_SCRIPT):self._fail(- _("Post-consume script does not exist."),+ MESSAGE_POST_CONSUME_SCRIPT_NOT_FOUND,f"Configured post-consume script "f"{settings.POST_CONSUME_SCRIPT} does not exist.")@@ -134,7 +147,7 @@ class Consumer(LoggingMixin):)).wait()except Exception as e:self._fail(- _("Error while executing post-consume script"),+ MESSAGE_POST_CONSUME_SCRIPT_ERROR,f"Error while executing post-consume script: {e}")@@ -158,7 +171,7 @@ class Consumer(LoggingMixin):self.override_tag_ids = override_tag_idsself.task_id = task_id or str(uuid.uuid4())- self._send_progress(0, 100, 'STARTING', _('Received new file'))+ self._send_progress(0, 100, 'STARTING', MESSAGE_NEW_FILE)# this is for grouping logging entries for this particular file# together.@@ -182,8 +195,7 @@ class Consumer(LoggingMixin):parser_class = get_parser_class_for_mime_type(mime_type)if not parser_class:self._fail(- _("File type %(type)s not supported") %- {'type': mime_type},+ MESSAGE_UNSUPPORTED_TYPE,f"Unsupported mime type {mime_type}")else:@@ -199,10 +211,10 @@ class Consumer(LoggingMixin):self.run_pre_consume_script()- def progress_callback(current_progress, max_progress, message):+ def progress_callback(current_progress, max_progress):# recalculate progress to be within 20 and 80p = int((current_progress / max_progress) * 50 + 20)- self._send_progress(p, 100, "WORKING", message)+ self._send_progress(p, 100, "WORKING")# This doesn't parse the document yet, but gives us a parser.@@ -219,13 +231,13 @@ class Consumer(LoggingMixin):archive_path = Nonetry:- self._send_progress(20, 100, 'WORKING', _('Parsing document...'))+ self._send_progress(20, 100, 'WORKING', MESSAGE_PARSING_DOCUMENT)self.log("debug", "Parsing {}...".format(self.filename))document_parser.parse(self.path, mime_type, self.filename)self.log("debug", f"Generating thumbnail for {self.filename}...")self._send_progress(70, 100, 'WORKING',- _('Generating thumbnail...'))+ MESSAGE_GENERATING_THUMBNAIL)thumbnail = document_parser.get_optimised_thumbnail(self.path, mime_type)@@ -233,7 +245,7 @@ class Consumer(LoggingMixin):date = document_parser.get_date()if not date:self._send_progress(90, 100, 'WORKING',- _('Getting date from document...'))+ MESSAGE_PARSE_DATE)date = parse_date(self.filename, text)archive_path = document_parser.get_archive_path()@@ -258,7 +270,7 @@ class Consumer(LoggingMixin):"warning",f"Cannot classify documents: {e}.")classifier = None- self._send_progress(95, 100, 'WORKING', _('Saving document...'))+ self._send_progress(95, 100, 'WORKING', MESSAGE_SAVE_DOCUMENT)# now that everything is done, we can start to store the document# in the system. This will be a transaction and reasonably fast.try:@@ -327,7 +339,7 @@ class Consumer(LoggingMixin):"Document {} consumption finished".format(document))- self._send_progress(100, 100, 'SUCCESS', _('Finished.'), document.id)+ self._send_progress(100, 100, 'SUCCESS', MESSAGE_FINISHED, document.id)return documentdiff --git a/src/documents/parsers.py b/src/documents/parsers.pyindex ddad6897a..3f0879b3c 100644--- a/src/documents/parsers.py+++ b/src/documents/parsers.py@@ -273,6 +273,11 @@ class DocumentParser(LoggingMixin):self.date = Noneself.progress_callback = progress_callback+ def progress(self, current, max):+ print(self.progress_callback)+ if self.progress_callback:+ self.progress_callback(current, max)+def extract_metadata(self, document_path, mime_type):return []diff --git a/src/locale/en-us/LC_MESSAGES/django.po b/src/locale/en-us/LC_MESSAGES/django.poindex 8513c577b..fdf3fd809 100644--- a/src/locale/en-us/LC_MESSAGES/django.po+++ b/src/locale/en-us/LC_MESSAGES/django.po@@ -8,7 +8,7 @@ msgid ""msgstr """Project-Id-Version: PACKAGE VERSION\n""Report-Msgid-Bugs-To: \n"-"POT-Creation-Date: 2021-01-27 17:57+0100\n"+"POT-Creation-Date: 2021-01-28 22:02+0100\n""PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n""Last-Translator: FULL NAME <EMAIL@ADDRESS>\n""Language-Team: LANGUAGE <[email protected]>\n"@@ -21,60 +21,6 @@ msgstr ""msgid "Documents"msgstr ""-#: documents/consumer.py:72-msgid "File not found"-msgstr "Datei nicht gefunden"--#: documents/consumer.py:83-msgid "Document already exists"-msgstr ""--#: documents/consumer.py:99-msgid "Pre-consume script does not exist."-msgstr ""--#: documents/consumer.py:107-msgid "Error while executing pre-consume script"-msgstr ""--#: documents/consumer.py:117-msgid "Post-consume script does not exist."-msgstr ""--#: documents/consumer.py:137-msgid "Error while executing post-consume script"-msgstr ""--#: documents/consumer.py:161-msgid "Received new file"-msgstr ""--#: documents/consumer.py:185 documents/serialisers.py:383-#, fuzzy, python-format-#| msgid "File type {type} not supported."-msgid "File type %(type)s not supported"-msgstr "Dateityp {type} wird nicht unterstützt"--#: documents/consumer.py:222-msgid "Parsing document..."-msgstr ""--#: documents/consumer.py:228-msgid "Generating thumbnail..."-msgstr ""--#: documents/consumer.py:236-msgid "Getting date from document..."-msgstr ""--#: documents/consumer.py:261-msgid "Saving document..."-msgstr ""--#: documents/consumer.py:330-msgid "Finished."-msgstr ""-#: documents/models.py:33msgid "Any word"msgstr ""@@ -392,6 +338,11 @@ msgstr ""msgid "filter rules"msgstr ""+#: documents/serialisers.py:383+#, python-format+msgid "File type %(type)s not supported"+msgstr ""+#: documents/templates/index.html:20msgid "Paperless-ng is loading..."msgstr ""@@ -674,6 +625,3 @@ msgstr ""#: paperless_mail/models.py:205msgid "assign this correspondent"msgstr ""--#~ msgid "Document is a duplicate"-#~ msgstr "Dokument existiert bereits"