mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
skeleton frontend_settings api endpoint
This commit is contained in:
parent
8f2687e390
commit
4b37c1963b
@ -11,6 +11,7 @@ from . import bulk_edit
|
||||
from .models import Correspondent
|
||||
from .models import Document
|
||||
from .models import DocumentType
|
||||
from .models import FrontendSettings
|
||||
from .models import MatchingModel
|
||||
from .models import SavedView
|
||||
from .models import SavedViewFilterRule
|
||||
@ -498,3 +499,21 @@ class BulkDownloadSerializer(DocumentListSerializer):
|
||||
"bzip2": zipfile.ZIP_BZIP2,
|
||||
"lzma": zipfile.ZIP_LZMA,
|
||||
}[compression]
|
||||
|
||||
|
||||
class FrontendSettingsViewSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = FrontendSettings
|
||||
depth = 1
|
||||
fields = [
|
||||
"id",
|
||||
"settings",
|
||||
]
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
super(FrontendSettingsViewSerializer, self).update(instance, validated_data)
|
||||
return instance
|
||||
|
||||
def create(self, validated_data):
|
||||
frontend_settings = FrontendSettings.objects.create(**validated_data)
|
||||
return frontend_settings
|
||||
|
@ -11,6 +11,7 @@ from unicodedata import normalize
|
||||
from urllib.parse import quote
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import Case
|
||||
from django.db.models import Count
|
||||
from django.db.models import IntegerField
|
||||
@ -70,6 +71,7 @@ from .serialisers import CorrespondentSerializer
|
||||
from .serialisers import DocumentListSerializer
|
||||
from .serialisers import DocumentSerializer
|
||||
from .serialisers import DocumentTypeSerializer
|
||||
from .serialisers import FrontendSettingsViewSerializer
|
||||
from .serialisers import PostDocumentSerializer
|
||||
from .serialisers import SavedViewSerializer
|
||||
from .serialisers import TagSerializer
|
||||
@ -715,3 +717,36 @@ class RemoteVersionView(GenericAPIView):
|
||||
"feature_is_set": feature_is_set,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class FrontendSettingsView(GenericAPIView):
|
||||
|
||||
permission_classes = (IsAuthenticated,)
|
||||
serializer_class = FrontendSettingsViewSerializer
|
||||
|
||||
def get(self, request, format=None):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
user = User.objects.get(pk=request.user.id)
|
||||
settings = []
|
||||
if hasattr(user, "frontend_settings"):
|
||||
settings = user.frontend_settings.settings
|
||||
return Response(
|
||||
{
|
||||
"user_id": user.id,
|
||||
"settings": settings,
|
||||
},
|
||||
)
|
||||
|
||||
def post(self, request, format=None):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
serializer.save(user=self.request.user)
|
||||
|
||||
return Response(
|
||||
{
|
||||
"success": True,
|
||||
},
|
||||
)
|
||||
|
@ -11,6 +11,7 @@ from documents.views import BulkDownloadView
|
||||
from documents.views import BulkEditView
|
||||
from documents.views import CorrespondentViewSet
|
||||
from documents.views import DocumentTypeViewSet
|
||||
from documents.views import FrontendSettingsView
|
||||
from documents.views import IndexView
|
||||
from documents.views import LogViewSet
|
||||
from documents.views import PostDocumentView
|
||||
@ -78,6 +79,11 @@ urlpatterns = [
|
||||
RemoteVersionView.as_view(),
|
||||
name="remoteversion",
|
||||
),
|
||||
re_path(
|
||||
r"^frontend_settings/",
|
||||
FrontendSettingsView.as_view(),
|
||||
name="frontend_settings",
|
||||
),
|
||||
path("token/", views.obtain_auth_token),
|
||||
]
|
||||
+ api_router.urls,
|
||||
|
Loading…
x
Reference in New Issue
Block a user