From 65e87c116f4d998ca60f92a1be42b8ad90ea0682 Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Tue, 20 Oct 2020 00:35:27 +0200 Subject: [PATCH] removed reminders, changed a bunch of stuff --- src/documents/admin.py | 51 ++-------------- src/documents/models.py | 1 - src/documents/serialisers.py | 16 ++--- src/documents/tests/test_matchables.py | 61 ------------------- src/paperless/settings.py | 22 +++---- src/paperless/urls.py | 2 - src/reminders/__init__.py | 0 src/reminders/admin.py | 20 ------ src/reminders/apps.py | 5 -- src/reminders/filters.py | 14 ----- src/reminders/migrations/0001_initial.py | 27 -------- .../migrations/0002_auto_20181007_1420.py | 19 ------ src/reminders/migrations/__init__.py | 0 src/reminders/models.py | 9 --- src/reminders/serialisers.py | 14 ----- src/reminders/tests.py | 3 - src/reminders/views.py | 22 ------- 17 files changed, 24 insertions(+), 262 deletions(-) delete mode 100644 src/documents/tests/test_matchables.py delete mode 100644 src/reminders/__init__.py delete mode 100644 src/reminders/admin.py delete mode 100644 src/reminders/apps.py delete mode 100644 src/reminders/filters.py delete mode 100644 src/reminders/migrations/0001_initial.py delete mode 100644 src/reminders/migrations/0002_auto_20181007_1420.py delete mode 100644 src/reminders/migrations/__init__.py delete mode 100644 src/reminders/models.py delete mode 100644 src/reminders/serialisers.py delete mode 100644 src/reminders/tests.py delete mode 100644 src/reminders/views.py diff --git a/src/documents/admin.py b/src/documents/admin.py index 4b247b399..b96487937 100755 --- a/src/documents/admin.py +++ b/src/documents/admin.py @@ -1,17 +1,11 @@ -from datetime import datetime, timedelta +from datetime import datetime from django.conf import settings -from django.contrib import admin, messages -from django.contrib.admin.templatetags.admin_urls import add_preserved_filters +from django.contrib import admin from django.contrib.auth.models import Group, User from django.db import models -from django.http import HttpResponseRedirect -from django.templatetags.static import static -from django.urls import reverse from django.utils.html import format_html, format_html_join -from django.utils.http import urlquote from django.utils.safestring import mark_safe -from djangoql.admin import DjangoQLSearchMixin from .models import Correspondent, Document, DocumentType, Log, Tag @@ -156,12 +150,7 @@ class DocumentTypeAdmin(CommonAdmin): document_count.admin_order_field = "document_count" -class DocumentAdmin(DjangoQLSearchMixin, CommonAdmin): - - class Media: - css = { - "all": ("paperless.css",) - } +class DocumentAdmin(CommonAdmin): search_fields = ("correspondent__name", "title", "content", "tags__name") readonly_fields = ("added", "file_type", "storage_type",) @@ -187,20 +176,6 @@ class DocumentAdmin(DjangoQLSearchMixin, CommonAdmin): return obj.created.date().strftime("%Y-%m-%d") created_.short_description = "Created" - @mark_safe - def thumbnail(self, obj): - return self._html_tag( - "a", - self._html_tag( - "img", - src=reverse("fetch", kwargs={"kind": "thumb", "pk": obj.pk}), - height=100, - alt="Thumbnail of {}".format(obj.file_name), - title=obj.file_name - ), - href=obj.download_url - ) - @mark_safe def tags_(self, obj): r = "" @@ -212,22 +187,6 @@ class DocumentAdmin(DjangoQLSearchMixin, CommonAdmin): ) return r - @mark_safe - def document(self, obj): - # TODO: is this method even used anymore? - return self._html_tag( - "a", - self._html_tag( - "img", - src=static("documents/img/{}.png".format(obj.file_type)), - width=22, - height=22, - alt=obj.file_type, - title=obj.file_name - ), - href=obj.download_url - ) - @staticmethod def _html_tag(kind, inside=None, **kwargs): attributes = format_html_join(' ', '{}="{}"', kwargs.items()) @@ -253,5 +212,5 @@ admin.site.register(Log, LogAdmin) # Unless we implement multi-user, these default registrations don't make sense. -#admin.site.unregister(Group) -#admin.site.unregister(User) +admin.site.unregister(Group) +admin.site.unregister(User) diff --git a/src/documents/models.py b/src/documents/models.py index f14f8bd20..e94a5c170 100755 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -13,7 +13,6 @@ from django.db import models from django.template.defaultfilters import slugify from django.utils import timezone from django.utils.text import slugify -from fuzzywuzzy import fuzz from collections import defaultdict from .managers import LogManager diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 03fe283c4..a6ecfccaa 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -36,21 +36,22 @@ class TagSerializer(serializers.HyperlinkedModelSerializer): "slug", "name", "colour", - "automatic_classification" + "automatic_classification", + "is_inbox_tag" ) -class CorrespondentField(serializers.HyperlinkedRelatedField): +class CorrespondentField(serializers.PrimaryKeyRelatedField): def get_queryset(self): return Correspondent.objects.all() -class TagsField(serializers.HyperlinkedRelatedField): +class TagsField(serializers.PrimaryKeyRelatedField): def get_queryset(self): return Tag.objects.all() -class DocumentTypeField(serializers.HyperlinkedRelatedField): +class DocumentTypeField(serializers.PrimaryKeyRelatedField): def get_queryset(self): return DocumentType.objects.all() @@ -58,10 +59,10 @@ class DocumentTypeField(serializers.HyperlinkedRelatedField): class DocumentSerializer(serializers.ModelSerializer): correspondent = CorrespondentField( - view_name="drf:correspondent-detail", allow_null=True) - tags = TagsField(view_name="drf:tag-detail", many=True) + allow_null=True) + tags = TagsField(many=True) document_type = DocumentTypeField( - view_name="drf:documenttype-detail", allow_null=True) + allow_null=True) class Meta: model = Document @@ -80,6 +81,7 @@ class DocumentSerializer(serializers.ModelSerializer): "file_name", "download_url", "thumbnail_url", + "archive_serial_number" ) diff --git a/src/documents/tests/test_matchables.py b/src/documents/tests/test_matchables.py deleted file mode 100644 index f917055c8..000000000 --- a/src/documents/tests/test_matchables.py +++ /dev/null @@ -1,61 +0,0 @@ -from random import randint - -from django.contrib.admin.models import LogEntry -from django.contrib.auth.models import User -from django.test import TestCase, override_settings - -from ..models import Correspondent, Document, Tag -from ..signals import document_consumption_finished - -@override_settings(POST_CONSUME_SCRIPT=None) -class TestDocumentConsumptionFinishedSignal(TestCase): - """ - We make use of document_consumption_finished, so we should test that it's - doing what we expect wrt to tag & correspondent matching. - """ - - def setUp(self): - TestCase.setUp(self) - User.objects.create_user(username='test_consumer', password='12345') - self.doc_contains = Document.objects.create( - content="I contain the keyword.", file_type="pdf") - - def test_tag_applied_any(self): - t1 = Tag.objects.create( - name="test", match="keyword", matching_algorithm=Tag.MATCH_ANY) - document_consumption_finished.send( - sender=self.__class__, document=self.doc_contains) - self.assertTrue(list(self.doc_contains.tags.all()) == [t1]) - - def test_tag_not_applied(self): - Tag.objects.create( - name="test", match="no-match", matching_algorithm=Tag.MATCH_ANY) - document_consumption_finished.send( - sender=self.__class__, document=self.doc_contains) - self.assertTrue(list(self.doc_contains.tags.all()) == []) - - def test_correspondent_applied(self): - correspondent = Correspondent.objects.create( - name="test", - match="keyword", - matching_algorithm=Correspondent.MATCH_ANY - ) - document_consumption_finished.send( - sender=self.__class__, document=self.doc_contains) - self.assertTrue(self.doc_contains.correspondent == correspondent) - - def test_correspondent_not_applied(self): - Tag.objects.create( - name="test", - match="no-match", - matching_algorithm=Correspondent.MATCH_ANY - ) - document_consumption_finished.send( - sender=self.__class__, document=self.doc_contains) - self.assertEqual(self.doc_contains.correspondent, None) - - def test_logentry_created(self): - document_consumption_finished.send( - sender=self.__class__, document=self.doc_contains) - - self.assertEqual(LogEntry.objects.count(), 1) diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 7712b376c..330579552 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -66,8 +66,6 @@ FORCE_SCRIPT_NAME = os.getenv("PAPERLESS_FORCE_SCRIPT_NAME") # Application definition INSTALLED_APPS = [ - "whitenoise.runserver_nostatic", - "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", @@ -79,19 +77,25 @@ INSTALLED_APPS = [ "paperless", "documents.apps.DocumentsConfig", - "reminders.apps.RemindersConfig", "paperless_tesseract.apps.PaperlessTesseractConfig", "paperless_text.apps.PaperlessTextConfig", "django.contrib.admin", "rest_framework", - "crispy_forms", + "rest_framework.authtoken", "django_filters", - "djangoql", ] +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.TokenAuthentication', + ] +} + if os.getenv("PAPERLESS_INSTALLED_APPS"): INSTALLED_APPS += os.getenv("PAPERLESS_INSTALLED_APPS").split(",") @@ -111,7 +115,7 @@ MIDDLEWARE = [ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' # We allow CORS from localhost:8080 -CORS_ORIGIN_WHITELIST = tuple(os.getenv("PAPERLESS_CORS_ALLOWED_HOSTS", "http://localhost:8080,https://localhost:8080,localhost:4200").split(",")) +CORS_ORIGIN_WHITELIST = tuple(os.getenv("PAPERLESS_CORS_ALLOWED_HOSTS", "http://localhost:8080,https://localhost:8080,http://localhost:4200").split(",")) # If auth is disabled, we just use our "bypass" authentication middleware if bool(os.getenv("PAPERLESS_DISABLE_LOGIN", "false").lower() in ("yes", "y", "1", "t", "true")): @@ -339,11 +343,5 @@ FILENAME_PARSE_TRANSFORMS = [] for t in json.loads(os.getenv("PAPERLESS_FILENAME_PARSE_TRANSFORMS", "[]")): FILENAME_PARSE_TRANSFORMS.append((re.compile(t["pattern"]), t["repl"])) -# Specify for how many years a correspondent is considered recent. Recent -# correspondents will be shown in a separate "Recent correspondents" filter as -# well. Set to 0 to disable this filter. -PAPERLESS_RECENT_CORRESPONDENT_YEARS = int(os.getenv( - "PAPERLESS_RECENT_CORRESPONDENT_YEARS", 0)) - # Specify the filename format for out files PAPERLESS_FILENAME_FORMAT = os.getenv("PAPERLESS_FILENAME_FORMAT") diff --git a/src/paperless/urls.py b/src/paperless/urls.py index d208b3470..b708bde30 100755 --- a/src/paperless/urls.py +++ b/src/paperless/urls.py @@ -16,14 +16,12 @@ from documents.views import ( TagViewSet, DocumentTypeViewSet ) -from reminders.views import ReminderViewSet router = DefaultRouter() router.register(r"correspondents", CorrespondentViewSet) router.register(r"document_types", DocumentTypeViewSet) router.register(r"documents", DocumentViewSet) router.register(r"logs", LogViewSet) -router.register(r"reminders", ReminderViewSet) router.register(r"tags", TagViewSet) urlpatterns = [ diff --git a/src/reminders/__init__.py b/src/reminders/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/reminders/admin.py b/src/reminders/admin.py deleted file mode 100644 index bc39e24aa..000000000 --- a/src/reminders/admin.py +++ /dev/null @@ -1,20 +0,0 @@ -from django.conf import settings -from django.contrib import admin - -from .models import Reminder - - -class ReminderAdmin(admin.ModelAdmin): - - class Media: - css = { - "all": ("paperless.css",) - } - - list_per_page = settings.PAPERLESS_LIST_PER_PAGE - list_display = ("date", "document", "note") - list_filter = ("date",) - list_editable = ("note",) - - -admin.site.register(Reminder, ReminderAdmin) diff --git a/src/reminders/apps.py b/src/reminders/apps.py deleted file mode 100644 index a745cad29..000000000 --- a/src/reminders/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class RemindersConfig(AppConfig): - name = "reminders" diff --git a/src/reminders/filters.py b/src/reminders/filters.py deleted file mode 100644 index 8ca8f4402..000000000 --- a/src/reminders/filters.py +++ /dev/null @@ -1,14 +0,0 @@ -from django_filters.rest_framework import CharFilter, FilterSet - -from .models import Reminder - - -class ReminderFilterSet(FilterSet): - - class Meta(object): - model = Reminder - fields = { - "document": ["exact"], - "date": ["gt", "lt", "gte", "lte", "exact"], - "note": ["istartswith", "iendswith", "icontains"] - } diff --git a/src/reminders/migrations/0001_initial.py b/src/reminders/migrations/0001_initial.py deleted file mode 100644 index 6daad4ef2..000000000 --- a/src/reminders/migrations/0001_initial.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.5 on 2017-03-25 15:58 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('documents', '0016_auto_20170325_1558'), - ] - - operations = [ - migrations.CreateModel( - name='Reminder', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('date', models.DateTimeField()), - ('note', models.TextField(blank=True)), - ('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='documents.Document')), - ], - ), - ] diff --git a/src/reminders/migrations/0002_auto_20181007_1420.py b/src/reminders/migrations/0002_auto_20181007_1420.py deleted file mode 100644 index 324764d2c..000000000 --- a/src/reminders/migrations/0002_auto_20181007_1420.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.0.8 on 2018-10-07 14:20 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('reminders', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='reminder', - name='document', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='documents.Document'), - ), - ] diff --git a/src/reminders/migrations/__init__.py b/src/reminders/migrations/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/reminders/models.py b/src/reminders/models.py deleted file mode 100644 index e8ac7020b..000000000 --- a/src/reminders/models.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.db import models - - -class Reminder(models.Model): - - document = models.ForeignKey( - "documents.Document", on_delete=models.PROTECT) - date = models.DateTimeField() - note = models.TextField(blank=True) diff --git a/src/reminders/serialisers.py b/src/reminders/serialisers.py deleted file mode 100644 index bf8dd09c2..000000000 --- a/src/reminders/serialisers.py +++ /dev/null @@ -1,14 +0,0 @@ -from documents.models import Document -from rest_framework import serializers - -from .models import Reminder - - -class ReminderSerializer(serializers.HyperlinkedModelSerializer): - - document = serializers.HyperlinkedRelatedField( - view_name="drf:document-detail", queryset=Document.objects) - - class Meta(object): - model = Reminder - fields = ("id", "document", "date", "note") diff --git a/src/reminders/tests.py b/src/reminders/tests.py deleted file mode 100644 index 7ce503c2d..000000000 --- a/src/reminders/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/src/reminders/views.py b/src/reminders/views.py deleted file mode 100644 index d2ead96b5..000000000 --- a/src/reminders/views.py +++ /dev/null @@ -1,22 +0,0 @@ -from django_filters.rest_framework import DjangoFilterBackend -from rest_framework.filters import OrderingFilter -from rest_framework.permissions import IsAuthenticated -from rest_framework.viewsets import ( - ModelViewSet, -) - -from .filters import ReminderFilterSet -from .models import Reminder -from .serialisers import ReminderSerializer -from paperless.views import StandardPagination - - -class ReminderViewSet(ModelViewSet): - model = Reminder - queryset = Reminder.objects - serializer_class = ReminderSerializer - pagination_class = StandardPagination - permission_classes = (IsAuthenticated,) - filter_backends = (DjangoFilterBackend, OrderingFilter) - filter_class = ReminderFilterSet - ordering_fields = ("date", "document")