A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Merge branch 'dev' into feature-websockets-status
jonaswinkler522ada88eafa
diff --cc Pipfileindex e9caaddd5,2e86f2a42..0e89efd9f--- a/Pipfile+++ b/Pipfile@@@ -35,9 -37,9 +37,12 @@@ scikit-learn="~=0.23.2whitenoise = "~=5.2.0"watchdog = "*"whoosh="~=2.7.4"+ inotifyrecursive = "~=0.3.4"+ ocrmypdf = "*"+ tqdm = "*"+channels = "~=3.0"+channels-redis = "*"+daphne = "~=3.0"[dev-packages]coveralls = "*"diff --cc src-ui/src/app/app.module.tsindex 2a70af813,1a2a76908..f421e2cd6--- a/src-ui/src/app/app.module.ts+++ b/src-ui/src/app/app.module.ts@@@ -45,7 -45,7 +45,8 @@@ import { SavedViewWidgetComponent } froimport { StatisticsWidgetComponent } from './components/dashboard/widgets/statistics-widget/statistics-widget.component';import { UploadFileWidgetComponent } from './components/dashboard/widgets/upload-file-widget/upload-file-widget.component';import { WidgetFrameComponent } from './components/dashboard/widgets/widget-frame/widget-frame.component';+ import { WelcomeWidgetComponent } from './components/dashboard/widgets/welcome-widget/welcome-widget.component';+import { ConsumerStatusWidgetComponent } from './components/dashboard/widgets/consumer-status-widget/consumer-status-widget.component';@NgModule({declarations: [@@@ -83,8 -83,8 +84,9 @@@SavedViewWidgetComponent,StatisticsWidgetComponent,UploadFileWidgetComponent,- ConsumerStatusWidgetComponent,- WidgetFrameComponent+ WidgetFrameComponent,- WelcomeWidgetComponent++ WelcomeWidgetComponent,++ ConsumerStatusWidgetComponent],imports: [BrowserModule,diff --cc src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.tsindex 405c82f7a,413df0ae4..f53e3ebfc--- a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts+++ b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts@@@ -1,8 -1,8 +1,10 @@@-import { Component, Input, OnInit } from '@angular/core';+import { Component, Input, OnDestroy, OnInit } from '@angular/core';+ import { Router } from '@angular/router';+import { Subscription } from 'rxjs';import { PaperlessDocument } from 'src/app/data/paperless-document';import { SavedViewConfig } from 'src/app/data/saved-view-config';+ import { DocumentListViewService } from 'src/app/services/document-list-view.service';+import { ConsumerStatusService } from 'src/app/services/consumer-status.service';import { DocumentService } from 'src/app/services/rest/document.service';@Component({@@@ -12,8 -12,11 +14,12 @@@})export class SavedViewWidgetComponent implements OnInit {- constructor(private documentService: DocumentService, private consumerStatusService: ConsumerStatusService) { }+ constructor(+ private documentService: DocumentService,+ private router: Router,- private list: DocumentListViewService) { }-++ private list: DocumentListViewService,++ private consumerStatusService: ConsumerStatusService) { }+@Input()savedView: SavedViewConfigdiff --cc src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.htmlindex 4e8049a69,50d844b36..c8beb1d28--- a/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html+++ b/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html@@@ -1,4 -1,6 +1,6 @@@<app-widget-frame title="Statistics">- <p class="card-text">Documents in inbox: {{statistics.documents_inbox}}</p>- <p class="card-text">Total documents: {{statistics.documents_total}}</p>+ <ng-container content>+ <p class="card-text">Documents in inbox: {{statistics.documents_inbox}}</p>+ <p class="card-text">Total documents: {{statistics.documents_total}}</p>+ </ng-container>-</app-widget-frame>+</app-widget-frame>diff --cc src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.tsindex cb13b2d74,1003f31db..97b4ffee8--- a/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts+++ b/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts@@@ -32,10 -29,18 +29,18 @@@ export class UploadFileWidgetComponentconst formData = new FormData()formData.append('document', file, file.name)this.documentService.uploadDocument(formData).subscribe(result => {- this.toastService.showInfo("The document has been uploaded and will be processed by the consumer shortly.")- this.toastService.showToast(Toast.make("Information", "The document has been uploaded and will be processed by the consumer shortly."))++ this.toastService.showInfo(The document has been uploaded and will be processed by the consumer shortly.")}, error => {- this.toastService.showError("An error has occured while uploading the document. Sorry!")+ switch (error.status) {+ case 400: {- this.toastService.showToast(Toast.makeError(`There was an error while uploading the document: ${error.error.document}`))++ this.toastService.showError(`There was an error while uploading the document: ${error.error.document}`)+ break;+ }+ default: {- this.toastService.showToast(Toast.makeError("An error has occured while uploading the document. Sorry!"))++ this.toastService.showError("An error has occured while uploading the document. Sorry!")+ break;+ }+ }})});}diff --cc src/documents/consumer.pyindex 8abee7918,7bae5c2a9..b57e81d06--- a/src/documents/consumer.py+++ b/src/documents/consumer.py@@@ -4,18 -4,17 +4,19 @@@ import logginimport osimport magic+from asgiref.sync import async_to_sync+from channels.layers import get_channel_layerfrom django.conf import settingsfrom django.db import transaction+ from django.db.models import Qfrom django.utils import timezone- from paperless.db import GnuPGfrom .classifier import DocumentClassifier, IncompatibleClassifierVersionError- from .file_handling import generate_filename, create_source_path_directory+ from .file_handling import create_source_path_directoryfrom .loggers import LoggingMixinfrom .models import Document, FileInfo, Correspondent, DocumentType, Tag- from .parsers import ParseError, get_parser_class_for_mime_type+ from .parsers import ParseError, get_parser_class_for_mime_type, \+ get_supported_file_extensions, parse_datefrom .signals import (document_consumption_finished,document_consumption_started@@@ -138,14 -108,9 +128,14 @@@ class Consumer(LoggingMixin)logging_group=self.logging_group)+ def progress_callback(current_progress, max_progress, message):+ # recalculate progress to be within 20 and 80+ p = int((current_progress / max_progress) * 60 + 20)+ self._send_progress(self.filename, p, 100, "WORKING", message)+# This doesn't parse the document yet, but gives us a parser.- document_parser = parser_class(self.path, self.logging_group, progress_callback)- document_parser = parser_class(self.logging_group)++ document_parser = parser_class(self.logging_group, progress_callback)# However, this already created working directories which we have to# clean up.@@@ -153,21 -118,24 +143,32 @@@# Parse the document. This may take some time.try:++ self._send_progress(self.filename, 20, 100, 'WORKING',++ 'Parsing document...')+ self.log("debug", "Parsing {}...".format(self.filename))+ document_parser.parse(self.path, mime_type)+self.log("debug", f"Generating thumbnail for {self.filename}...")- self._send_progress(self.filename, 10, 100, 'WORKING',++ self._send_progress(self.filename, 70, 100, 'WORKING',+ 'Generating thumbnail...')- thumbnail = document_parser.get_optimised_thumbnail()- self.log("debug", "Parsing {}...".format(self.filename))- self._send_progress(self.filename, 20, 100, 'WORKING',- 'Getting text from document...')+ thumbnail = document_parser.get_optimised_thumbnail(+ self.path, mime_type)+text = document_parser.get_text()- self._send_progress(self.filename, 80, 100, 'WORKING',- 'Getting date from document...')date = document_parser.get_date()+ if not date:++ self._send_progress(self.filename, 90, 100, 'WORKING',++ 'Getting date from document...')+ date = parse_date(self.filename, text)+ archive_path = document_parser.get_archive_path()+except ParseError as e:document_parser.cleanup()+ self.log(+ "error",+ f"Error while consuming document {self.filename}: {e}")+ self._send_progress(self.filename, 100, 100, 'FAILED',+ "Failed: {}".format(e))raise ConsumerError(e)# Prepare the document classifier.@@@ -183,8 -151,7 +184,8 @@@logging.getLogger(__name__).warning("Cannot classify documents: {}.".format(e))classifier = None- self._send_progress(self.filename, 85, 100, 'WORKING',-++ self._send_progress(self.filename, 95, 100, 'WORKING',+ 'Storing the 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:@@@ -221,8 -207,11 +241,13 @@@self.log("debug", "Deleting file {}".format(self.path))os.unlink(self.path)except Exception as e:+ self.log(+ "error",+ f"The following error occured while consuming "+ f"{self.filename}: {e}"+ )+ self._send_progress(self.filename, 100, 100, 'FAILED',+ "Failed: {}".format(e))raise ConsumerError(e)finally:document_parser.cleanup()diff --cc src/documents/parsers.pyindex 81198868d,36ede3cce..e525221dd--- a/src/documents/parsers.py+++ b/src/documents/parsers.py@@@ -134,15 -207,23 +207,24 @@@ class DocumentParser(LoggingMixin)`paperless_tesseract.parsers` for inspiration."""- def __init__(self, path, logging_group, progress_callback):- def __init__(self, logging_group):++ def __init__(self, logging_group, progress_callback):super().__init__()self.logging_group = logging_group- self.document_path = pathself.tempdir = tempfile.mkdtemp(prefix="paperless-", dir=settings.SCRATCH_DIR)++ self.archive_path = None+ self.text = None+ self.date = None+ self.progress_callback = progress_callback- def get_thumbnail(self):+ def parse(self, document_path, mime_type):+ raise NotImplementedError()++ def get_archive_path(self):+ return self.archive_path++ def get_thumbnail(self, document_path, mime_type):"""Returns the path to a file we can use as a thumbnail for this document."""diff --cc src/paperless/urls.pyindex f422729fa,9b390b139..2d75907a2--- a/src/paperless/urls.py+++ b/src/paperless/urls.py@@@ -4,9 -4,9 +4,10 @@@ from django.contrib.auth.decorators impfrom django.urls import path, re_pathfrom django.views.decorators.csrf import csrf_exemptfrom django.views.generic import RedirectView+ from rest_framework.authtoken import viewsfrom rest_framework.routers import DefaultRouter+from paperless.consumers import StatusConsumerfrom documents.views import (CorrespondentViewSet,DocumentViewSet,