Skip to content
Snippets Groups Projects
Commit 6615f829 authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Jfk fixes

parent 0be6fff2
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,8 @@ from rest_framework.generics import \
ListAPIView, RetrieveAPIView, CreateAPIView, RetrieveDestroyAPIView # , RetrieveUpdateAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.exceptions import APIException
from rest_framework.response import Response
from rest_framework import status
from django.conf import settings
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
......@@ -136,8 +138,12 @@ class TextElementCreate(CreateAPIView):
def perform_create(self, serializer):
element_type = serializer.validated_data['type']
if element_type not in (ElementType.Paragraph, ElementType.Line,
ElementType.Word, ElementType.Character):
if element_type not in (
ElementType.Page,
ElementType.Paragraph,
ElementType.Line,
ElementType.Word,
ElementType.Character):
raise APIException(detail="This endpoint can only import transcriptions.")
element = serializer.validated_data['element']
# Create a zone on the page's image
......@@ -162,6 +168,14 @@ class TextElementCreate(CreateAPIView):
Transcription.INDEX_TYPE,
Transcription.objects.filter(id=ts.id)
)
return ts
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
obj = self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response({'id': obj.id}, status=status.HTTP_201_CREATED, headers=headers)
class TranscriptionSearch(ListAPIView):
......
......@@ -29,6 +29,7 @@ class Indexer(object):
"type": "nested",
"properties": {
"id": {"type": "text"},
"type": {"type": "text"},
"score": {"type": "float"},
"text": {"type": "text"}
}
......
......@@ -294,6 +294,7 @@ class Act(Element):
'transcriptions': [
{
'id': t.id,
'type': t.type.value,
'score': t.score,
'text': t.text
}
......@@ -329,6 +330,7 @@ class Transcription(Element):
"""
return {
'id': self.id, # TODO: Could be removed? (can use _id instead)
'type': self.type.value,
'score': self.score,
'line': self.line,
'text': self.text,
......
......@@ -61,7 +61,7 @@ class TestTextElementCreate(APITestCase):
"""
self.client.force_login(self.user)
response = self.client.post(reverse('api:element'), format='json', data={
"type": "page",
"type": "register",
"element": str(self.page.id),
"polygon": [(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)],
"text": "NEKUDOTAYIM",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment