Browse Source

Replace RelationTypeOld with RelationType in label_type app

pull/1703/head
Hironsan 2 years ago
parent
commit
969b3ef299
3 changed files with 15 additions and 32 deletions
  1. 29
      backend/label_types/serializers.py
  2. 2
      backend/label_types/urls.py
  3. 16
      backend/label_types/views.py

29
backend/label_types/serializers.py

@ -1,7 +1,7 @@
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from .models import CategoryType, LabelType, RelationTypeOld, SpanType
from .models import CategoryType, LabelType, RelationType, SpanType
class LabelSerializer(serializers.ModelSerializer):
@ -54,33 +54,16 @@ class LabelSerializer(serializers.ModelSerializer):
class CategoryTypeSerializer(LabelSerializer):
class Meta:
model = CategoryType
fields = (
"id",
"text",
"prefix_key",
"suffix_key",
"background_color",
"text_color",
)
fields = LabelSerializer.Meta.fields
class SpanTypeSerializer(LabelSerializer):
class Meta:
model = SpanType
fields = (
"id",
"text",
"prefix_key",
"suffix_key",
"background_color",
"text_color",
)
fields = LabelSerializer.Meta.fields
class RelationTypesSerializer(serializers.ModelSerializer):
def validate(self, attrs):
return super().validate(attrs)
class RelationTypeSerializer(serializers.ModelSerializer):
class Meta:
model = RelationTypeOld
fields = ("id", "color", "name")
model = RelationType
fields = LabelSerializer.Meta.fields

2
backend/label_types/urls.py

@ -21,5 +21,5 @@ urlpatterns = [
path(route="span-type-upload", view=SpanTypeUploadAPI.as_view(), name="span_type_upload"),
path(route="relation_types", view=RelationTypeList.as_view(), name="relation_types_list"),
path(route="relation_type-upload", view=RelationTypeUploadAPI.as_view(), name="relation_type-upload"),
path(route="relation_types/<int:relation_type_id>", view=RelationTypeDetail.as_view(), name="relation_type_detail"),
path(route="relation_types/<int:label_id>", view=RelationTypeDetail.as_view(), name="relation_type_detail"),
]

16
backend/label_types/views.py

@ -11,11 +11,11 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from .exceptions import LabelValidationError
from .models import CategoryType, LabelType, RelationTypeOld, SpanType
from .models import CategoryType, LabelType, RelationType, SpanType
from .serializers import (
CategoryTypeSerializer,
LabelSerializer,
RelationTypesSerializer,
RelationTypeSerializer,
SpanTypeSerializer,
)
from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly
@ -74,14 +74,14 @@ class SpanTypeDetail(generics.RetrieveUpdateDestroyAPIView):
class RelationTypeList(LabelList):
model = RelationTypeOld
serializer_class = RelationTypesSerializer
model = RelationType
serializer_class = RelationTypeSerializer
class RelationTypeDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = RelationTypeOld.objects.all()
serializer_class = RelationTypesSerializer
lookup_url_kwarg = "relation_type_id"
queryset = RelationType.objects.all()
serializer_class = RelationTypeSerializer
lookup_url_kwarg = "label_id"
permission_classes = [IsAuthenticated & (IsProjectAdmin | IsProjectStaffAndReadOnly)]
@ -116,4 +116,4 @@ class SpanTypeUploadAPI(LabelUploadAPI):
class RelationTypeUploadAPI(LabelUploadAPI):
serializer_class = RelationTypesSerializer
serializer_class = RelationTypeSerializer
Loading…
Cancel
Save