not sure if this works

This commit is contained in:
jonaswinkler 2020-11-29 23:00:52 +01:00
parent 32186e0de1
commit fd4c9a1758
2 changed files with 23 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import os
import re
import tempfile
from datetime import datetime
from time import mktime
@ -11,6 +12,17 @@ from pathvalidate import validate_filename, ValidationError
from documents.parsers import is_mime_type_supported
class BuldEditForm(forms.Form):
def clean_ids(self):
ids = self.cleaned_data.get("ids")
if not re.match(r"[0-9,]+", ids):
raise forms.ValidationError("id list invalid")
id_list = [int(id) for id in ids.split(",")]
class UploadForm(forms.Form):

View File

@ -93,6 +93,10 @@ class DocumentTypeViewSet(ModelViewSet):
ordering_fields = ("name", "matching_algorithm", "match", "document_count")
class BulkEditForm(object):
pass
class DocumentViewSet(RetrieveModelMixin,
UpdateModelMixin,
DestroyModelMixin,
@ -149,6 +153,13 @@ class DocumentViewSet(RetrieveModelMixin,
else:
return HttpResponseBadRequest(str(form.errors))
@action(methods=['post'], detail=False)
def bulk_edit(self, request, pk=None):
form = BulkEditForm(data=request.POST)
if not form.is_valid():
return HttpResponseBadRequest("")
return Response({'asd': request.POST['content']})
@action(methods=['get'], detail=True)
def metadata(self, request, pk=None):
try: