Browse Source

Implement me API

pull/151/head
Hironsan 5 years ago
parent
commit
92f7c5a75c
3 changed files with 19 additions and 1 deletions
  1. 10
      app/server/api.py
  2. 2
      app/server/api_urls.py
  3. 8
      app/server/serializers.py

10
app/server/api.py

@ -14,13 +14,21 @@ from rest_framework_csv.renderers import CSVRenderer
from .filters import DocumentFilter
from .models import Project, Label, Document
from .permissions import IsAdminUserAndWriteOnly, IsProjectUser, IsOwnAnnotation
from .serializers import ProjectSerializer, LabelSerializer, DocumentSerializer
from .serializers import ProjectSerializer, LabelSerializer, DocumentSerializer, UserSerializer
from .serializers import ProjectPolymorphicSerializer
from .utils import CSVParser, JSONParser, PlainTextParser, CoNLLParser
from .utils import JSONLRenderer
from .utils import JSONPainter, CSVPainter
class Me(APIView):
permission_classes = (IsAuthenticated,)
def get(self, request, *args, **kwargs):
serializer = UserSerializer(request.user, context={'request': request})
return Response(serializer.data)
class ProjectList(generics.ListCreateAPIView):
queryset = Project.objects.all()
serializer_class = ProjectPolymorphicSerializer

2
app/server/api_urls.py

@ -1,6 +1,7 @@
from django.urls import path
from rest_framework.urlpatterns import format_suffix_patterns
from .api import Me
from .api import ProjectList, ProjectDetail
from .api import LabelList, LabelDetail
from .api import DocumentList, DocumentDetail
@ -10,6 +11,7 @@ from .api import StatisticsAPI
urlpatterns = [
path('me', Me.as_view(), name='me'),
path('projects', ProjectList.as_view(), name='project_list'),
path('projects/<int:project_id>', ProjectDetail.as_view(), name='project_detail'),
path('projects/<int:project_id>/statistics',

8
app/server/serializers.py

@ -1,3 +1,4 @@
from django.contrib.auth import get_user_model
from rest_framework import serializers
from rest_polymorphic.serializers import PolymorphicSerializer
@ -6,6 +7,13 @@ from .models import TextClassificationProject, SequenceLabelingProject, Seq2seqP
from .models import DocumentAnnotation, SequenceAnnotation, Seq2seqAnnotation
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()
fields = ('id', 'username', 'first_name', 'last_name', 'email', 'is_superuser')
class LabelSerializer(serializers.ModelSerializer):
class Meta:

Loading…
Cancel
Save