2022-08-26 20:04:45 +03:00
|
|
|
from rest_framework import generics
|
2022-08-27 07:38:54 +03:00
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework.generics import get_object_or_404
|
2022-08-26 20:04:45 +03:00
|
|
|
from rest_framework.parsers import MultiPartParser, FormParser
|
|
|
|
|
2022-08-27 11:59:23 +03:00
|
|
|
from checker.api.serializers import (
|
|
|
|
DocxSerializer,
|
|
|
|
DocxStateSerializer,
|
|
|
|
WordDocxSerializer,
|
|
|
|
WordDocxStateSerializer,
|
|
|
|
)
|
|
|
|
from checker.models import Docx, ParagraphType, WordDocx
|
2022-08-26 20:04:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
class ListCreateDocxApiView(generics.ListCreateAPIView):
|
|
|
|
parser_classes = [FormParser, MultiPartParser]
|
|
|
|
serializer_class = DocxSerializer
|
|
|
|
queryset = Docx.objects.all()
|
2022-08-27 07:38:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
class GetDocxState(generics.RetrieveAPIView):
|
|
|
|
lookup_field = "uuid"
|
|
|
|
queryset = Docx.objects.all()
|
|
|
|
serializer_class = DocxStateSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class RetireDocxSerializer(APIView):
|
|
|
|
def get(self, request, uuid):
|
|
|
|
doc = get_object_or_404(Docx, uuid=uuid)
|
|
|
|
res = {}
|
2022-08-27 11:13:36 +03:00
|
|
|
paragraphs = ParagraphType.objects.all()
|
2022-08-27 07:38:54 +03:00
|
|
|
for p in paragraphs:
|
2022-08-27 11:13:36 +03:00
|
|
|
res[p.name] = [(x.text, x.score) for x in p.paragraphs.filter(docx=doc)]
|
2022-08-27 07:38:54 +03:00
|
|
|
return Response(res)
|
|
|
|
|
2022-08-27 11:59:23 +03:00
|
|
|
|
|
|
|
class ListCreateWordDocxApiView(generics.ListCreateAPIView):
|
|
|
|
parser_classes = [FormParser, MultiPartParser]
|
|
|
|
serializer_class = WordDocxSerializer
|
|
|
|
queryset = WordDocx.objects.all()
|
|
|
|
|
|
|
|
|
|
|
|
class GetWordDocxState(generics.RetrieveAPIView):
|
|
|
|
lookup_field = "uuid"
|
|
|
|
queryset = WordDocx.objects.all()
|
|
|
|
serializer_class = WordDocxStateSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class RetireWordDocxSerializer(APIView):
|
|
|
|
# TODO create base class
|
|
|
|
def get(self, request, uuid):
|
|
|
|
doc = get_object_or_404(WordDocx, uuid=uuid)
|
|
|
|
res = {}
|
|
|
|
paragraphs = ParagraphType.objects.all()
|
|
|
|
for p in paragraphs:
|
|
|
|
res[p.name] = [(x.text, x.score) for x in p.word_paragraphs.filter(docx=doc)]
|
|
|
|
return Response(res)
|