From 47cf5655b3c5b8753e693b56fe41e2caeb867d11 Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Tue, 27 Oct 2020 17:35:52 +0100 Subject: [PATCH] implement api file uploading (basic) --- src/documents/views.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/documents/views.py b/src/documents/views.py index ee0fbe403..8f759f2a7 100755 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1,5 +1,5 @@ from django.db.models import Count, Max -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseBadRequest from django.views.decorators.cache import cache_control from django.views.generic import TemplateView from django_filters.rest_framework import DjangoFilterBackend @@ -31,6 +31,7 @@ from .filters import ( ) import documents.index as index +from .forms import UploadForm from .models import Correspondent, Document, Log, Tag, DocumentType from .serialisers import ( CorrespondentSerializer, @@ -122,8 +123,13 @@ class DocumentViewSet(RetrieveModelMixin, @action(methods=['post'], detail=False) def post_document(self, request, pk=None): - #TODO: implement document upload - return Response("not implemented yet", status=500) + #TODO: is this a good implementation? + form = UploadForm(data=request.POST, files=request.FILES) + if form.is_valid(): + form.save() + return Response("OK") + else: + return HttpResponseBadRequest(str(form.errors)) @action(methods=['get'], detail=True) def preview(self, request, pk=None):