mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Merge branch 'dev' into machine-learning
This commit is contained in:
		
							
								
								
									
										17
									
								
								src/documents/filters.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										17
									
								
								src/documents/filters.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,6 +1,6 @@ | ||||
| from django_filters.rest_framework import CharFilter, FilterSet | ||||
|  | ||||
| from .models import Correspondent, Document, Tag | ||||
| from .models import Correspondent, Document, Tag, DocumentType | ||||
|  | ||||
|  | ||||
| class CorrespondentFilterSet(FilterSet): | ||||
| @@ -29,6 +29,19 @@ class TagFilterSet(FilterSet): | ||||
|         } | ||||
|  | ||||
|  | ||||
| class DocumentTypeFilterSet(FilterSet): | ||||
|  | ||||
|     class Meta(object): | ||||
|         model = DocumentType | ||||
|         fields = { | ||||
|             "name": [ | ||||
|                 "startswith", "endswith", "contains", | ||||
|                 "istartswith", "iendswith", "icontains" | ||||
|             ], | ||||
|             "slug": ["istartswith", "iendswith", "icontains"] | ||||
|         } | ||||
|  | ||||
|  | ||||
| class DocumentFilterSet(FilterSet): | ||||
|  | ||||
|     CHAR_KWARGS = { | ||||
| @@ -46,6 +59,8 @@ class DocumentFilterSet(FilterSet): | ||||
|     correspondent__slug = CharFilter(name="correspondent__slug", **CHAR_KWARGS) | ||||
|     tags__name = CharFilter(name="tags__name", **CHAR_KWARGS) | ||||
|     tags__slug = CharFilter(name="tags__slug", **CHAR_KWARGS) | ||||
|     document_type__name = CharFilter(name="document_type__name", **CHAR_KWARGS) | ||||
|     document_type__slug = CharFilter(name="document_type__slug", **CHAR_KWARGS) | ||||
|  | ||||
|     class Meta(object): | ||||
|         model = Document | ||||
|   | ||||
							
								
								
									
										5
									
								
								src/documents/management/commands/document_exporter.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										5
									
								
								src/documents/management/commands/document_exporter.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -6,7 +6,7 @@ import shutil | ||||
| from django.core.management.base import BaseCommand, CommandError | ||||
| from django.core import serializers | ||||
|  | ||||
| from documents.models import Document, Correspondent, Tag | ||||
| from documents.models import Document, Correspondent, Tag, DocumentType | ||||
| from paperless.db import GnuPG | ||||
|  | ||||
| from ...mixins import Renderable | ||||
| @@ -91,6 +91,9 @@ class Command(Renderable, BaseCommand): | ||||
|         manifest += json.loads(serializers.serialize( | ||||
|             "json", Tag.objects.all())) | ||||
|  | ||||
|         manifest += json.loads(serializers.serialize( | ||||
|             "json", DocumentType.objects.all())) | ||||
|  | ||||
|         with open(os.path.join(self.target, "manifest.json"), "w") as f: | ||||
|             json.dump(manifest, f, indent=2) | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| from rest_framework import serializers | ||||
|  | ||||
| from .models import Correspondent, Tag, Document, Log | ||||
| from .models import Correspondent, Tag, Document, Log, DocumentType | ||||
|  | ||||
|  | ||||
| class CorrespondentSerializer(serializers.HyperlinkedModelSerializer): | ||||
| @@ -10,6 +10,13 @@ class CorrespondentSerializer(serializers.HyperlinkedModelSerializer): | ||||
|         fields = ("id", "slug", "name", "automatic_classification") | ||||
|  | ||||
|  | ||||
| class DocumentTypeSerializer(serializers.HyperlinkedModelSerializer): | ||||
|  | ||||
|     class Meta(object): | ||||
|         model = DocumentType | ||||
|         fields = ("id", "slug", "name") | ||||
|  | ||||
|  | ||||
| class TagSerializer(serializers.HyperlinkedModelSerializer): | ||||
|  | ||||
|     class Meta(object): | ||||
| @@ -28,17 +35,25 @@ class TagsField(serializers.HyperlinkedRelatedField): | ||||
|         return Tag.objects.all() | ||||
|  | ||||
|  | ||||
| class DocumentTypeField(serializers.HyperlinkedRelatedField): | ||||
|     def get_queryset(self): | ||||
|         return DocumentType.objects.all() | ||||
|  | ||||
|  | ||||
| class DocumentSerializer(serializers.ModelSerializer): | ||||
|  | ||||
|     correspondent = CorrespondentField( | ||||
|         view_name="drf:correspondent-detail", allow_null=True) | ||||
|     tags = TagsField(view_name="drf:tag-detail", many=True) | ||||
|     document_type = DocumentTypeField( | ||||
|         view_name="drf:documenttype-detail", allow_null=True) | ||||
|  | ||||
|     class Meta(object): | ||||
|         model = Document | ||||
|         fields = ( | ||||
|             "id", | ||||
|             "correspondent", | ||||
|             "document_type", | ||||
|             "title", | ||||
|             "content", | ||||
|             "file_type", | ||||
|   | ||||
							
								
								
									
										19
									
								
								src/documents/views.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										19
									
								
								src/documents/views.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -18,15 +18,15 @@ from rest_framework.viewsets import ( | ||||
|     ReadOnlyModelViewSet | ||||
| ) | ||||
|  | ||||
| from .filters import CorrespondentFilterSet, DocumentFilterSet, TagFilterSet | ||||
| from .filters import CorrespondentFilterSet, DocumentFilterSet, TagFilterSet, DocumentTypeFilterSet | ||||
| from .forms import UploadForm | ||||
| from .models import Correspondent, Document, Log, Tag | ||||
| from .models import Correspondent, Document, Log, Tag, DocumentType | ||||
| from .serialisers import ( | ||||
|     CorrespondentSerializer, | ||||
|     DocumentSerializer, | ||||
|     LogSerializer, | ||||
|     TagSerializer | ||||
| ) | ||||
|     TagSerializer, | ||||
|     DocumentTypeSerializer) | ||||
|  | ||||
|  | ||||
| class IndexView(TemplateView): | ||||
| @@ -108,6 +108,17 @@ class TagViewSet(ModelViewSet): | ||||
|     ordering_fields = ("name", "slug") | ||||
|  | ||||
|  | ||||
| class DocumentTypeViewSet(ModelViewSet): | ||||
|     model = DocumentType | ||||
|     queryset = DocumentType.objects.all() | ||||
|     serializer_class = DocumentTypeSerializer | ||||
|     pagination_class = StandardPagination | ||||
|     permission_classes = (IsAuthenticated,) | ||||
|     filter_backends = (DjangoFilterBackend, OrderingFilter) | ||||
|     filter_class = DocumentTypeFilterSet | ||||
|     ordering_fields = ("name", "slug") | ||||
|  | ||||
|  | ||||
| class DocumentViewSet(RetrieveModelMixin, | ||||
|                       UpdateModelMixin, | ||||
|                       DestroyModelMixin, | ||||
|   | ||||
| @@ -12,12 +12,13 @@ from documents.views import ( | ||||
|     FetchView, | ||||
|     LogViewSet, | ||||
|     PushView, | ||||
|     TagViewSet | ||||
| ) | ||||
|     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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonas Winkler
					Jonas Winkler