mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Runs the pre-commit hooks over all the Python files
This commit is contained in:
@@ -1 +1,4 @@
|
||||
from .checks import paths_check, binaries_check
|
||||
from .checks import binaries_check
|
||||
from .checks import paths_check
|
||||
|
||||
__all__ = ["binaries_check", "paths_check"]
|
||||
|
@@ -9,14 +9,14 @@ from django.core.asgi import get_asgi_application
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "paperless.settings")
|
||||
django_asgi_app = get_asgi_application()
|
||||
|
||||
from channels.auth import AuthMiddlewareStack # NOQA: E402
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter # NOQA: E402
|
||||
from channels.auth import AuthMiddlewareStack # noqa: E402
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter # noqa: E402
|
||||
|
||||
from paperless.urls import websocket_urlpatterns # NOQA: E402
|
||||
from paperless.urls import websocket_urlpatterns # noqa: E402
|
||||
|
||||
application = ProtocolTypeRouter(
|
||||
{
|
||||
"http": get_asgi_application(),
|
||||
"websocket": AuthMiddlewareStack(URLRouter(websocket_urlpatterns)),
|
||||
}
|
||||
},
|
||||
)
|
||||
|
@@ -1,9 +1,9 @@
|
||||
from django.conf import settings
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth.middleware import RemoteUserMiddleware
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
from rest_framework import authentication
|
||||
from django.contrib.auth.middleware import RemoteUserMiddleware
|
||||
|
||||
|
||||
class AutoLoginMiddleware(MiddlewareMixin):
|
||||
@@ -25,7 +25,7 @@ class AngularApiAuthenticationOverride(authentication.BaseAuthentication):
|
||||
settings.DEBUG
|
||||
and "Referer" in request.headers
|
||||
and request.headers["Referer"].startswith("http://localhost:4200/")
|
||||
): # NOQA: E501
|
||||
):
|
||||
user = User.objects.filter(is_staff=True).first()
|
||||
print("Auto-Login with user {}".format(user))
|
||||
return (user, None)
|
||||
|
@@ -3,7 +3,9 @@ import shutil
|
||||
import stat
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.checks import Error, Warning, register
|
||||
from django.core.checks import Error
|
||||
from django.core.checks import register
|
||||
from django.core.checks import Warning
|
||||
|
||||
exists_message = "{} is set but doesn't exist."
|
||||
exists_hint = "Create a directory at {}"
|
||||
@@ -19,11 +21,12 @@ def path_check(var, directory):
|
||||
if directory:
|
||||
if not os.path.isdir(directory):
|
||||
messages.append(
|
||||
Error(exists_message.format(var), exists_hint.format(directory))
|
||||
Error(exists_message.format(var), exists_hint.format(directory)),
|
||||
)
|
||||
else:
|
||||
test_file = os.path.join(
|
||||
directory, f"__paperless_write_test_{os.getpid()}__"
|
||||
directory,
|
||||
f"__paperless_write_test_{os.getpid()}__",
|
||||
)
|
||||
try:
|
||||
with open(test_file, "w"):
|
||||
@@ -34,9 +37,9 @@ def path_check(var, directory):
|
||||
writeable_message.format(var),
|
||||
writeable_hint.format(
|
||||
f"\n{stat.filemode(os.stat(directory).st_mode)} "
|
||||
f"{directory}\n"
|
||||
f"{directory}\n",
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
finally:
|
||||
if os.path.isfile(test_file):
|
||||
@@ -88,8 +91,8 @@ def debug_mode_check(app_configs, **kwargs):
|
||||
"security issue, since it puts security overides in place which "
|
||||
"are meant to be only used during development. This "
|
||||
"also means that paperless will tell anyone various "
|
||||
"debugging information when something goes wrong."
|
||||
)
|
||||
"debugging information when something goes wrong.",
|
||||
),
|
||||
]
|
||||
else:
|
||||
return []
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import json
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
from channels.exceptions import DenyConnection, AcceptConnection
|
||||
from channels.exceptions import AcceptConnection
|
||||
from channels.exceptions import DenyConnection
|
||||
from channels.generic.websocket import WebsocketConsumer
|
||||
|
||||
|
||||
@@ -14,13 +15,15 @@ class StatusConsumer(WebsocketConsumer):
|
||||
raise DenyConnection()
|
||||
else:
|
||||
async_to_sync(self.channel_layer.group_add)(
|
||||
"status_updates", self.channel_name
|
||||
"status_updates",
|
||||
self.channel_name,
|
||||
)
|
||||
raise AcceptConnection()
|
||||
|
||||
def disconnect(self, close_code):
|
||||
async_to_sync(self.channel_layer.group_discard)(
|
||||
"status_updates", self.channel_name
|
||||
"status_updates",
|
||||
self.channel_name,
|
||||
)
|
||||
|
||||
def status_update(self, event):
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import gnupg
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
from django.conf import settings
|
||||
|
||||
from paperless import version
|
||||
|
||||
|
||||
|
@@ -5,9 +5,8 @@ import os
|
||||
import re
|
||||
|
||||
from concurrent_log_handler.queue import setup_logging_queues
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Tap paperless.conf if it's available
|
||||
if os.path.exists("../paperless.conf"):
|
||||
@@ -68,7 +67,8 @@ MODEL_FILE = os.path.join(DATA_DIR, "classification_model.pickle")
|
||||
LOGGING_DIR = os.getenv("PAPERLESS_LOGGING_DIR", os.path.join(DATA_DIR, "log"))
|
||||
|
||||
CONSUMPTION_DIR = os.getenv(
|
||||
"PAPERLESS_CONSUMPTION_DIR", os.path.join(BASE_DIR, "..", "consume")
|
||||
"PAPERLESS_CONSUMPTION_DIR",
|
||||
os.path.join(BASE_DIR, "..", "consume"),
|
||||
)
|
||||
|
||||
# This will be created if it doesn't exist
|
||||
@@ -119,7 +119,7 @@ REST_FRAMEWORK = {
|
||||
|
||||
if DEBUG:
|
||||
REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"].append(
|
||||
"paperless.auth.AngularApiAuthenticationOverride"
|
||||
"paperless.auth.AngularApiAuthenticationOverride",
|
||||
)
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -191,7 +191,8 @@ if AUTO_LOGIN_USERNAME:
|
||||
|
||||
ENABLE_HTTP_REMOTE_USER = __get_boolean("PAPERLESS_ENABLE_HTTP_REMOTE_USER")
|
||||
HTTP_REMOTE_USER_HEADER_NAME = os.getenv(
|
||||
"PAPERLESS_HTTP_REMOTE_USER_HEADER_NAME", "HTTP_REMOTE_USER"
|
||||
"PAPERLESS_HTTP_REMOTE_USER_HEADER_NAME",
|
||||
"HTTP_REMOTE_USER",
|
||||
)
|
||||
|
||||
if ENABLE_HTTP_REMOTE_USER:
|
||||
@@ -201,7 +202,7 @@ if ENABLE_HTTP_REMOTE_USER:
|
||||
"django.contrib.auth.backends.ModelBackend",
|
||||
]
|
||||
REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"].append(
|
||||
"rest_framework.authentication.RemoteUserAuthentication"
|
||||
"rest_framework.authentication.RemoteUserAuthentication",
|
||||
)
|
||||
|
||||
# X-Frame options for embedded PDF display:
|
||||
@@ -212,7 +213,7 @@ else:
|
||||
|
||||
# We allow CORS from localhost:8080
|
||||
CORS_ALLOWED_ORIGINS = tuple(
|
||||
os.getenv("PAPERLESS_CORS_ALLOWED_HOSTS", "http://localhost:8000").split(",")
|
||||
os.getenv("PAPERLESS_CORS_ALLOWED_HOSTS", "http://localhost:8000").split(","),
|
||||
)
|
||||
|
||||
if DEBUG:
|
||||
@@ -223,7 +224,8 @@ if DEBUG:
|
||||
# Paperless on a closed network. However, if you're putting this anywhere
|
||||
# public, you should change the key to something unique and verbose.
|
||||
SECRET_KEY = os.getenv(
|
||||
"PAPERLESS_SECRET_KEY", "e11fl1oa-*ytql8p)(06fbj4ukrlo+n7k&q5+$1md7i+mge=ee"
|
||||
"PAPERLESS_SECRET_KEY",
|
||||
"e11fl1oa-*ytql8p)(06fbj4ukrlo+n7k&q5+$1md7i+mge=ee",
|
||||
)
|
||||
|
||||
_allowed_hosts = os.getenv("PAPERLESS_ALLOWED_HOSTS")
|
||||
@@ -268,7 +270,7 @@ DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": os.path.join(DATA_DIR, "db.sqlite3"),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
if os.getenv("PAPERLESS_DBHOST"):
|
||||
@@ -423,7 +425,8 @@ def default_threads_per_worker(task_workers):
|
||||
|
||||
|
||||
THREADS_PER_WORKER = os.getenv(
|
||||
"PAPERLESS_THREADS_PER_WORKER", default_threads_per_worker(TASK_WORKERS)
|
||||
"PAPERLESS_THREADS_PER_WORKER",
|
||||
default_threads_per_worker(TASK_WORKERS),
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
@@ -435,7 +438,7 @@ CONSUMER_POLLING = int(os.getenv("PAPERLESS_CONSUMER_POLLING", 0))
|
||||
CONSUMER_POLLING_DELAY = int(os.getenv("PAPERLESS_CONSUMER_POLLING_DELAY", 5))
|
||||
|
||||
CONSUMER_POLLING_RETRY_COUNT = int(
|
||||
os.getenv("PAPERLESS_CONSUMER_POLLING_RETRY_COUNT", 5)
|
||||
os.getenv("PAPERLESS_CONSUMER_POLLING_RETRY_COUNT", 5),
|
||||
)
|
||||
|
||||
CONSUMER_DELETE_DUPLICATES = __get_boolean("PAPERLESS_CONSUMER_DELETE_DUPLICATES")
|
||||
@@ -448,8 +451,8 @@ CONSUMER_IGNORE_PATTERNS = list(
|
||||
os.getenv(
|
||||
"PAPERLESS_CONSUMER_IGNORE_PATTERNS",
|
||||
'[".DS_STORE/*", "._*", ".stfolder/*"]',
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
CONSUMER_SUBDIRS_AS_TAGS = __get_boolean("PAPERLESS_CONSUMER_SUBDIRS_AS_TAGS")
|
||||
@@ -479,7 +482,7 @@ OCR_DESKEW = __get_boolean("PAPERLESS_OCR_DESKEW", "true")
|
||||
OCR_ROTATE_PAGES = __get_boolean("PAPERLESS_OCR_ROTATE_PAGES", "true")
|
||||
|
||||
OCR_ROTATE_PAGES_THRESHOLD = float(
|
||||
os.getenv("PAPERLESS_OCR_ROTATE_PAGES_THRESHOLD", 12.0)
|
||||
os.getenv("PAPERLESS_OCR_ROTATE_PAGES_THRESHOLD", 12.0),
|
||||
)
|
||||
|
||||
OCR_USER_ARGS = os.getenv("PAPERLESS_OCR_USER_ARGS", "{}")
|
||||
@@ -536,7 +539,8 @@ THUMBNAIL_FONT_NAME = os.getenv(
|
||||
PAPERLESS_TIKA_ENABLED = __get_boolean("PAPERLESS_TIKA_ENABLED", "NO")
|
||||
PAPERLESS_TIKA_ENDPOINT = os.getenv("PAPERLESS_TIKA_ENDPOINT", "http://localhost:9998")
|
||||
PAPERLESS_TIKA_GOTENBERG_ENDPOINT = os.getenv(
|
||||
"PAPERLESS_TIKA_GOTENBERG_ENDPOINT", "http://localhost:3000"
|
||||
"PAPERLESS_TIKA_GOTENBERG_ENDPOINT",
|
||||
"http://localhost:3000",
|
||||
)
|
||||
|
||||
if PAPERLESS_TIKA_ENABLED:
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from django.test import override_settings
|
||||
from django.test import TestCase
|
||||
from documents.tests.utils import DirectoriesMixin
|
||||
from paperless import binaries_check, paths_check
|
||||
from paperless import binaries_check
|
||||
from paperless import paths_check
|
||||
from paperless.checks import debug_mode_check
|
||||
|
||||
|
||||
@@ -20,7 +21,9 @@ class TestChecks(DirectoriesMixin, TestCase):
|
||||
self.assertEqual(paths_check(None), [])
|
||||
|
||||
@override_settings(
|
||||
MEDIA_ROOT="uuh", DATA_DIR="whatever", CONSUMPTION_DIR="idontcare"
|
||||
MEDIA_ROOT="uuh",
|
||||
DATA_DIR="whatever",
|
||||
CONSUMPTION_DIR="idontcare",
|
||||
)
|
||||
def test_paths_check_dont_exist(self):
|
||||
msgs = paths_check(None)
|
||||
|
@@ -2,8 +2,8 @@ from unittest import mock
|
||||
|
||||
from channels.layers import get_channel_layer
|
||||
from channels.testing import WebsocketCommunicator
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from django.test import override_settings
|
||||
from django.test import TestCase
|
||||
from paperless.asgi import application
|
||||
|
||||
|
||||
@@ -46,7 +46,8 @@ class TestWebSockets(TestCase):
|
||||
|
||||
channel_layer = get_channel_layer()
|
||||
await channel_layer.group_send(
|
||||
"status_updates", {"type": "status_update", "data": message}
|
||||
"status_updates",
|
||||
{"type": "status_update", "data": message},
|
||||
)
|
||||
|
||||
response = await communicator.receive_json_from()
|
||||
|
@@ -1,34 +1,30 @@
|
||||
from django.conf import settings
|
||||
from django.conf.urls import include
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.urls import path, re_path
|
||||
from django.urls import path
|
||||
from django.urls import re_path
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import RedirectView
|
||||
from documents.views import BulkDownloadView
|
||||
from documents.views import BulkEditView
|
||||
from documents.views import CorrespondentViewSet
|
||||
from documents.views import DocumentTypeViewSet
|
||||
from documents.views import IndexView
|
||||
from documents.views import LogViewSet
|
||||
from documents.views import PostDocumentView
|
||||
from documents.views import SavedViewViewSet
|
||||
from documents.views import SearchAutoCompleteView
|
||||
from documents.views import SelectionDataView
|
||||
from documents.views import StatisticsView
|
||||
from documents.views import TagViewSet
|
||||
from documents.views import UnifiedSearchViewSet
|
||||
from paperless.consumers import StatusConsumer
|
||||
from paperless.views import FaviconView
|
||||
from rest_framework.authtoken import views
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from paperless.consumers import StatusConsumer
|
||||
from documents.views import (
|
||||
CorrespondentViewSet,
|
||||
UnifiedSearchViewSet,
|
||||
LogViewSet,
|
||||
TagViewSet,
|
||||
DocumentTypeViewSet,
|
||||
IndexView,
|
||||
SearchAutoCompleteView,
|
||||
StatisticsView,
|
||||
PostDocumentView,
|
||||
SavedViewViewSet,
|
||||
BulkEditView,
|
||||
SelectionDataView,
|
||||
BulkDownloadView,
|
||||
)
|
||||
from paperless.views import FaviconView
|
||||
|
||||
api_router = DefaultRouter()
|
||||
api_router.register(r"correspondents", CorrespondentViewSet)
|
||||
api_router.register(r"document_types", DocumentTypeViewSet)
|
||||
@@ -62,7 +58,9 @@ urlpatterns = [
|
||||
name="post_document",
|
||||
),
|
||||
re_path(
|
||||
r"^documents/bulk_edit/", BulkEditView.as_view(), name="bulk_edit"
|
||||
r"^documents/bulk_edit/",
|
||||
BulkEditView.as_view(),
|
||||
name="bulk_edit",
|
||||
),
|
||||
re_path(
|
||||
r"^documents/selection_data/",
|
||||
@@ -76,7 +74,7 @@ urlpatterns = [
|
||||
),
|
||||
path("token/", views.obtain_auth_token),
|
||||
]
|
||||
+ api_router.urls
|
||||
+ api_router.urls,
|
||||
),
|
||||
),
|
||||
re_path(r"^favicon.ico$", FaviconView.as_view(), name="favicon"),
|
||||
@@ -88,35 +86,37 @@ urlpatterns = [
|
||||
re_path(
|
||||
r"^doc/(?P<pk>\d+)$",
|
||||
RedirectView.as_view(
|
||||
url=settings.BASE_URL + "api/documents/%(pk)s/download/"
|
||||
url=settings.BASE_URL + "api/documents/%(pk)s/download/",
|
||||
),
|
||||
),
|
||||
re_path(
|
||||
r"^thumb/(?P<pk>\d+)$",
|
||||
RedirectView.as_view(
|
||||
url=settings.BASE_URL + "api/documents/%(pk)s/thumb/"
|
||||
url=settings.BASE_URL + "api/documents/%(pk)s/thumb/",
|
||||
),
|
||||
),
|
||||
re_path(
|
||||
r"^preview/(?P<pk>\d+)$",
|
||||
RedirectView.as_view(
|
||||
url=settings.BASE_URL + "api/documents/%(pk)s/preview/"
|
||||
url=settings.BASE_URL + "api/documents/%(pk)s/preview/",
|
||||
),
|
||||
),
|
||||
]
|
||||
],
|
||||
),
|
||||
),
|
||||
re_path(
|
||||
r"^push$",
|
||||
csrf_exempt(
|
||||
RedirectView.as_view(url=settings.BASE_URL + "api/documents/post_document/")
|
||||
RedirectView.as_view(
|
||||
url=settings.BASE_URL + "api/documents/post_document/",
|
||||
),
|
||||
),
|
||||
),
|
||||
# Frontend assets TODO: this is pretty bad, but it works.
|
||||
path(
|
||||
"assets/<path:path>",
|
||||
RedirectView.as_view(
|
||||
url=settings.STATIC_URL + "frontend/en-US/assets/%(path)s"
|
||||
url=settings.STATIC_URL + "frontend/en-US/assets/%(path)s",
|
||||
),
|
||||
),
|
||||
# TODO: with localization, this is even worse! :/
|
||||
|
@@ -14,7 +14,11 @@ class StandardPagination(PageNumberPagination):
|
||||
class FaviconView(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
favicon = os.path.join(
|
||||
os.path.dirname(__file__), "static", "paperless", "img", "favicon.ico"
|
||||
os.path.dirname(__file__),
|
||||
"static",
|
||||
"paperless",
|
||||
"img",
|
||||
"favicon.ico",
|
||||
)
|
||||
with open(favicon, "rb") as f:
|
||||
return HttpResponse(f, content_type="image/x-icon")
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
from uvicorn.workers import UvicornWorker
|
||||
|
||||
from django.conf import settings
|
||||
from uvicorn.workers import UvicornWorker
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "paperless.settings")
|
||||
|
||||
|
@@ -6,7 +6,6 @@ It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
Reference in New Issue
Block a user