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
# serve to show the default.
import sys
import os
__version__ = None
exec(open("../src/paperless/version.py").read())

View File

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

View File

@ -1,4 +1,3 @@
from django.db import transaction
import datetime
import hashlib
import logging
@ -7,11 +6,12 @@ import re
import uuid
from django.conf import settings
from django.db import transaction
from django.utils import timezone
from paperless.db import GnuPG
from .classifier import DocumentClassifier
from .models import Document, FileInfo, Tag
from .models import Document, FileInfo
from .parsers import ParseError
from .signals import (
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 documents.classifier import DocumentClassifier
from documents.models import Document, Tag
from documents.models import Document
from ...mixins import Renderable
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.utils import timezone
from documents.classifier import DocumentClassifier
from .. import index, matching
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 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

View File

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

View File

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