mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
A crude API is in place
This commit is contained in:
parent
809fb8fa1f
commit
17d3a44952
@ -3,14 +3,14 @@ from rest_framework import serializers
|
|||||||
from .models import Sender, Tag, Document
|
from .models import Sender, Tag, Document
|
||||||
|
|
||||||
|
|
||||||
class SenderSerializer(serializers.ModelSerializer):
|
class SenderSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
model = Sender
|
model = Sender
|
||||||
fields = ("id", "slug", "name")
|
fields = ("id", "slug", "name")
|
||||||
|
|
||||||
|
|
||||||
class TagSerializer(serializers.ModelSerializer):
|
class TagSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
model = Tag
|
model = Tag
|
||||||
@ -20,8 +20,10 @@ class TagSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class DocumentSerializer(serializers.ModelSerializer):
|
class DocumentSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
sender = serializers.HyperlinkedModelSerializer(read_only=True)
|
sender = serializers.HyperlinkedRelatedField(
|
||||||
tags = serializers.HyperlinkedModelSerializer(read_only=True)
|
read_only=True, view_name="drf:sender-detail", allow_null=True)
|
||||||
|
tags = serializers.HyperlinkedRelatedField(
|
||||||
|
read_only=True, view_name="drf:tag-detail", many=True)
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
model = Document
|
model = Document
|
||||||
|
@ -3,6 +3,7 @@ from django.template.defaultfilters import slugify
|
|||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.views.generic import FormView, DetailView
|
from django.views.generic import FormView, DetailView
|
||||||
|
|
||||||
|
from rest_framework.pagination import PageNumberPagination
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from paperless.db import GnuPG
|
from paperless.db import GnuPG
|
||||||
@ -57,16 +58,28 @@ class PushView(FormView):
|
|||||||
return HttpResponse("0")
|
return HttpResponse("0")
|
||||||
|
|
||||||
|
|
||||||
|
class StandardPagination(PageNumberPagination):
|
||||||
|
page_size = 25
|
||||||
|
page_size_query_param = "page-size"
|
||||||
|
max_page_size = 100000
|
||||||
|
|
||||||
|
|
||||||
class SenderViewSet(ModelViewSet):
|
class SenderViewSet(ModelViewSet):
|
||||||
model = Sender
|
model = Sender
|
||||||
|
queryset = Sender.objects.all()
|
||||||
serializer_class = SenderSerializer
|
serializer_class = SenderSerializer
|
||||||
|
pagination_class = StandardPagination
|
||||||
|
|
||||||
|
|
||||||
class TagViewSet(ModelViewSet):
|
class TagViewSet(ModelViewSet):
|
||||||
model = Tag
|
model = Tag
|
||||||
|
queryset = Tag.objects.all()
|
||||||
serializer_class = TagSerializer
|
serializer_class = TagSerializer
|
||||||
|
pagination_class = StandardPagination
|
||||||
|
|
||||||
|
|
||||||
class DocumentViewSet(ModelViewSet):
|
class DocumentViewSet(ModelViewSet):
|
||||||
model = Document
|
model = Document
|
||||||
|
queryset = Document.objects.all()
|
||||||
serializer_class = DocumentSerializer
|
serializer_class = DocumentSerializer
|
||||||
|
pagination_class = StandardPagination
|
||||||
|
@ -33,9 +33,9 @@ urlpatterns = [
|
|||||||
# API
|
# API
|
||||||
url(
|
url(
|
||||||
r"^api/auth/",
|
r"^api/auth/",
|
||||||
include('rest_framework.urls', namespace='rest_framework')
|
include('rest_framework.urls', namespace="rest_framework")
|
||||||
),
|
),
|
||||||
url(r"^api/", include(router.urls)),
|
url(r"^api/", include(router.urls, namespace="drf")),
|
||||||
|
|
||||||
# File downloads
|
# File downloads
|
||||||
url(r"^fetch/(?P<pk>\d+)$", PdfView.as_view(), name="fetch"),
|
url(r"^fetch/(?P<pk>\d+)$", PdfView.as_view(), name="fetch"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user