removed reminders, changed a bunch of stuff

This commit is contained in:
Jonas Winkler
2020-10-20 00:35:27 +02:00
parent 4ed8263127
commit d365e8ac22
17 changed files with 24 additions and 262 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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"
)

View File

@@ -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)