A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
refactor: break document-only stuff into the paperless app
Daniel Quinn426919fa9f5b
diff --git a/src/documents/mixins.py b/src/documents/mixins.pyindex a031dd50f..4d4e9783f 100644--- a/src/documents/mixins.py+++ b/src/documents/mixins.py@@ -1,8 +1,3 @@-from django.contrib.auth.mixins import AccessMixin-from django.contrib.auth import authenticate, login-import base64--class Renderable(object):"""A handy mixin to make it easier/cleaner to print output based on a@@ -12,46 +7,3 @@ class Renderable(object):def _render(self, text, verbosity):if self.verbosity >= verbosity:print(text)---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()diff --git a/src/documents/views.py b/src/documents/views.pyindex 3598472af..b57a0a571 100644--- a/src/documents/views.py+++ b/src/documents/views.py@@ -2,15 +2,16 @@ from django.http import HttpResponsefrom django.views.decorators.csrf import csrf_exemptfrom django.views.generic import DetailView, FormView, TemplateViewfrom django_filters.rest_framework import DjangoFilterBackend-from rest_framework.filters import SearchFilter, OrderingFilterfrom paperless.db import GnuPG+from paperless.mixins import SessionOrBasicAuthMixin+from paperless.views import StandardPagination+from rest_framework.filters import OrderingFilter, SearchFilterfrom rest_framework.mixins import (DestroyModelMixin,ListModelMixin,RetrieveModelMixin,UpdateModelMixin)-from rest_framework.pagination import PageNumberPaginationfrom rest_framework.permissions import IsAuthenticatedfrom rest_framework.viewsets import (GenericViewSet,@@ -27,7 +28,6 @@ from .serialisers import (LogSerializer,TagSerializer)-from .mixins import SessionOrBasicAuthMixinclass IndexView(TemplateView):@@ -92,12 +92,6 @@ class PushView(SessionOrBasicAuthMixin, FormView):return HttpResponse("0")-class StandardPagination(PageNumberPagination):- page_size = 25- page_size_query_param = "page-size"- max_page_size = 100000--class CorrespondentViewSet(ModelViewSet):model = Correspondentqueryset = Correspondent.objects.all()diff --git a/src/paperless/mixins.py b/src/paperless/mixins.pynew file mode 100644index 000000000..f4f1fcdec--- /dev/null+++ b/src/paperless/mixins.py@@ -0,0 +1,46 @@+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()diff --git a/src/paperless/views.py b/src/paperless/views.pynew file mode 100644index 000000000..d2ce23aaf--- /dev/null+++ b/src/paperless/views.py@@ -0,0 +1,7 @@+from rest_framework.pagination import PageNumberPagination+++class StandardPagination(PageNumberPagination):+ page_size = 25+ page_size_query_param = "page-size"+ max_page_size = 100000