removed unused code, small fixes

This commit is contained in:
Jonas Winkler 2020-11-02 18:20:04 +01:00
parent 3bef72c717
commit 7d282a4e4e
10 changed files with 19 additions and 94 deletions

View File

@ -12,9 +12,6 @@
# All configuration values have a default; values that are commented out # All configuration values have a default; values that are commented out
# serve to show the default. # serve to show the default.
import sys
import os
__version__ = None __version__ = None
exec(open("../src/paperless/version.py").read()) exec(open("../src/paperless/version.py").read())

View File

@ -75,7 +75,6 @@ class DocumentAdmin(admin.ModelAdmin):
def tags_(self, obj): def tags_(self, obj):
r = "" r = ""
for tag in obj.tags.all(): for tag in obj.tags.all():
colour = tag.get_colour_display()
r += self._html_tag( r += self._html_tag(
"span", "span",
tag.slug + ", " tag.slug + ", "

View File

@ -1,4 +1,3 @@
from django.db import transaction
import datetime import datetime
import hashlib import hashlib
import logging import logging
@ -7,11 +6,12 @@ import re
import uuid import uuid
from django.conf import settings from django.conf import settings
from django.db import transaction
from django.utils import timezone from django.utils import timezone
from paperless.db import GnuPG from paperless.db import GnuPG
from .classifier import DocumentClassifier from .classifier import DocumentClassifier
from .models import Document, FileInfo
from .models import Document, FileInfo, Tag
from .parsers import ParseError from .parsers import ParseError
from .signals import ( from .signals import (
document_consumer_declaration, document_consumer_declaration,

View File

@ -1,24 +0,0 @@
from django.core.management.base import BaseCommand
from documents.models import Document, Tag
from ...mixins import Renderable
class Command(Renderable, BaseCommand):
help = """
This will rename all documents to match the latest filename format.
""".replace(" ", "")
def __init__(self, *args, **kwargs):
self.verbosity = 0
BaseCommand.__init__(self, *args, **kwargs)
def handle(self, *args, **options):
self.verbosity = options["verbosity"]
for document in Document.objects.all():
# Saving the document again will generate a new filename and rename
document.save()

View File

@ -3,8 +3,7 @@ import logging
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from documents.classifier import DocumentClassifier from documents.classifier import DocumentClassifier
from documents.models import Document, Tag from documents.models import Document
from ...mixins import Renderable from ...mixins import Renderable
from ...signals.handlers import set_correspondent, set_document_type, set_tags from ...signals.handlers import set_correspondent, set_document_type, set_tags

View File

@ -8,7 +8,6 @@ from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.utils import timezone from django.utils import timezone
from documents.classifier import DocumentClassifier
from .. import index, matching from .. import index, matching
from ..models import Document, Tag from ..models import Document, Tag

View File

@ -1,46 +0,0 @@
from django.contrib.auth.mixins import AccessMixin
from django.contrib.auth import authenticate, login
import base64
class SessionOrBasicAuthMixin(AccessMixin):
"""
Session or Basic Authentication mixin for Django.
It determines if the requester is already logged in or if they have
provided proper http-authorization and returning the view if all goes
well, otherwise responding with a 401.
Base for mixin found here: https://djangosnippets.org/snippets/3073/
"""
def dispatch(self, request, *args, **kwargs):
# check if user is authenticated via the session
if request.user.is_authenticated:
# Already logged in, just return the view.
return super(SessionOrBasicAuthMixin, self).dispatch(
request, *args, **kwargs
)
# apparently not authenticated via session, maybe via HTTP Basic?
if 'HTTP_AUTHORIZATION' in request.META:
auth = request.META['HTTP_AUTHORIZATION'].split()
if len(auth) == 2:
# NOTE: Support for only basic authentication
if auth[0].lower() == "basic":
authString = base64.b64decode(auth[1]).decode('utf-8')
uname, passwd = authString.split(':')
user = authenticate(username=uname, password=passwd)
if user is not None:
if user.is_active:
login(request, user)
request.user = user
return super(
SessionOrBasicAuthMixin, self
).dispatch(
request, *args, **kwargs
)
# nope, really not authenticated
return self.handle_no_permission()

View File

@ -260,7 +260,7 @@ OCR_LANGUAGE = os.getenv("PAPERLESS_OCR_LANGUAGE", "eng")
OCR_THREADS = int(os.getenv("PAPERLESS_OCR_THREADS", 4)) OCR_THREADS = int(os.getenv("PAPERLESS_OCR_THREADS", 4))
# OCR all documents? # OCR all documents?
OCR_ALWAYS = __get_boolean("PAPERLESS_OCR_ALWAYS", False) OCR_ALWAYS = __get_boolean("PAPERLESS_OCR_ALWAYS", "false")
# GNUPG needs a home directory for some reason # GNUPG needs a home directory for some reason

View File

@ -160,6 +160,7 @@ class RasterisedDocumentParser(DocumentParser):
guess = langdetect.detect(text) guess = langdetect.detect(text)
return guess return guess
except Exception as e: except Exception as e:
self.log('debug', "Language detection failed with: {}".format(e))
return None return None
def _ocr(self, imgs, lang): def _ocr(self, imgs, lang):

View File

@ -27,28 +27,28 @@ class TestDate(TestCase):
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_date_format_1(self): def test_date_format_1(self):
input_file = os.path.join(self.SAMPLE_FILES, "") input_file = os.path.join(self.SAMPLE_FILES, "")
document = RasterisedDocumentParser(input_file) document = RasterisedDocumentParser(input_file, None)
document._text = "lorem ipsum 130218 lorem ipsum" document._text = "lorem ipsum 130218 lorem ipsum"
self.assertEqual(document.get_date(), None) self.assertEqual(document.get_date(), None)
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_date_format_2(self): def test_date_format_2(self):
input_file = os.path.join(self.SAMPLE_FILES, "") input_file = os.path.join(self.SAMPLE_FILES, "")
document = RasterisedDocumentParser(input_file) document = RasterisedDocumentParser(input_file, None)
document._text = "lorem ipsum 2018 lorem ipsum" document._text = "lorem ipsum 2018 lorem ipsum"
self.assertEqual(document.get_date(), None) self.assertEqual(document.get_date(), None)
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_date_format_3(self): def test_date_format_3(self):
input_file = os.path.join(self.SAMPLE_FILES, "") input_file = os.path.join(self.SAMPLE_FILES, "")
document = RasterisedDocumentParser(input_file) document = RasterisedDocumentParser(input_file, None)
document._text = "lorem ipsum 20180213 lorem ipsum" document._text = "lorem ipsum 20180213 lorem ipsum"
self.assertEqual(document.get_date(), None) self.assertEqual(document.get_date(), None)
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_date_format_4(self): def test_date_format_4(self):
input_file = os.path.join(self.SAMPLE_FILES, "") input_file = os.path.join(self.SAMPLE_FILES, "")
document = RasterisedDocumentParser(input_file) document = RasterisedDocumentParser(input_file, None)
document._text = "lorem ipsum 13.02.2018 lorem ipsum" document._text = "lorem ipsum 13.02.2018 lorem ipsum"
date = document.get_date() date = document.get_date()
self.assertEqual( self.assertEqual(
@ -62,7 +62,7 @@ class TestDate(TestCase):
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_date_format_5(self): def test_date_format_5(self):
input_file = os.path.join(self.SAMPLE_FILES, "") input_file = os.path.join(self.SAMPLE_FILES, "")
document = RasterisedDocumentParser(input_file) document = RasterisedDocumentParser(input_file, None)
document._text = ( document._text = (
"lorem ipsum 130218, 2018, 20180213 and lorem 13.02.2018 lorem " "lorem ipsum 130218, 2018, 20180213 and lorem 13.02.2018 lorem "
"ipsum" "ipsum"
@ -79,7 +79,7 @@ class TestDate(TestCase):
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_date_format_6(self): def test_date_format_6(self):
input_file = os.path.join(self.SAMPLE_FILES, "") input_file = os.path.join(self.SAMPLE_FILES, "")
document = RasterisedDocumentParser(input_file) document = RasterisedDocumentParser(input_file, None)
document._text = ( document._text = (
"lorem ipsum\n" "lorem ipsum\n"
"Wohnort\n" "Wohnort\n"
@ -96,7 +96,7 @@ class TestDate(TestCase):
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_date_format_7(self): def test_date_format_7(self):
input_file = os.path.join(self.SAMPLE_FILES, "") input_file = os.path.join(self.SAMPLE_FILES, "")
document = RasterisedDocumentParser(input_file) document = RasterisedDocumentParser(input_file, None)
document._text = ( document._text = (
"lorem ipsum\n" "lorem ipsum\n"
"März 2019\n" "März 2019\n"
@ -114,7 +114,7 @@ class TestDate(TestCase):
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_date_format_8(self): def test_date_format_8(self):
input_file = os.path.join(self.SAMPLE_FILES, "") input_file = os.path.join(self.SAMPLE_FILES, "")
document = RasterisedDocumentParser(input_file) document = RasterisedDocumentParser(input_file, None)
document._text = ( document._text = (
"lorem ipsum\n" "lorem ipsum\n"
"Wohnort\n" "Wohnort\n"
@ -138,7 +138,7 @@ class TestDate(TestCase):
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_date_format_9(self): def test_date_format_9(self):
input_file = os.path.join(self.SAMPLE_FILES, "") input_file = os.path.join(self.SAMPLE_FILES, "")
document = RasterisedDocumentParser(input_file) document = RasterisedDocumentParser(input_file, None)
document._text = ( document._text = (
"lorem ipsum\n" "lorem ipsum\n"
"27. Nullmonth 2020\n" "27. Nullmonth 2020\n"
@ -159,7 +159,7 @@ class TestDate(TestCase):
) )
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_crazy_date_past(self, *args): def test_crazy_date_past(self, *args):
document = RasterisedDocumentParser("/dev/null") document = RasterisedDocumentParser("/dev/null", None)
document.get_text() document.get_text()
self.assertIsNone(document.get_date()) self.assertIsNone(document.get_date())
@ -169,7 +169,7 @@ class TestDate(TestCase):
) )
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_crazy_date_future(self, *args): def test_crazy_date_future(self, *args):
document = RasterisedDocumentParser("/dev/null") document = RasterisedDocumentParser("/dev/null", None)
document.get_text() document.get_text()
self.assertIsNone(document.get_date()) self.assertIsNone(document.get_date())
@ -179,7 +179,7 @@ class TestDate(TestCase):
) )
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_crazy_date_with_spaces(self, *args): def test_crazy_date_with_spaces(self, *args):
document = RasterisedDocumentParser("/dev/null") document = RasterisedDocumentParser("/dev/null", None)
document.get_text() document.get_text()
self.assertIsNone(document.get_date()) self.assertIsNone(document.get_date())
@ -195,6 +195,6 @@ class TestDate(TestCase):
) )
@mock.patch(MOCK_SCRATCH, SCRATCH) @mock.patch(MOCK_SCRATCH, SCRATCH)
def test_filename_date_parse_invalid(self, *args): def test_filename_date_parse_invalid(self, *args):
document = RasterisedDocumentParser("/tmp/20 408000l 2475 - test.pdf") document = RasterisedDocumentParser("/tmp/20 408000l 2475 - test.pdf", None)
document.get_text() document.get_text()
self.assertIsNone(document.get_date()) self.assertIsNone(document.get_date())