Browse Source

Add AutoLabelingTemplateAPI to retrieve base templates

pull/1206/head
Hironsan 4 years ago
parent
commit
8df8392df9
2 changed files with 19 additions and 0 deletions
  1. 6
      app/api/urls.py
  2. 13
      app/api/views.py

6
app/api/urls.py

@ -11,6 +11,7 @@ from .views import CommentList, CommentDetail
from .views import TextUploadAPI, TextDownloadAPI, CloudUploadAPI from .views import TextUploadAPI, TextDownloadAPI, CloudUploadAPI
from .views import StatisticsAPI from .views import StatisticsAPI
from .views import RoleMappingList, RoleMappingDetail, Roles from .views import RoleMappingList, RoleMappingDetail, Roles
from .views import AutoLabelingTemplateAPI
urlpatterns = [ urlpatterns = [
path('health', Health.as_view(), name='health'), path('health', Health.as_view(), name='health'),
@ -52,6 +53,11 @@ urlpatterns = [
RoleMappingList.as_view(), name='rolemapping_list'), RoleMappingList.as_view(), name='rolemapping_list'),
path('projects/<int:project_id>/roles/<int:rolemapping_id>', path('projects/<int:project_id>/roles/<int:rolemapping_id>',
RoleMappingDetail.as_view(), name='rolemapping_detail'), RoleMappingDetail.as_view(), name='rolemapping_detail'),
path(
route='projects/<int:project_id>/auto-labeling-templates',
view=AutoLabelingTemplateAPI.as_view(),
name='auto_labeling_templates'
)
] ]
# urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'xml']) # urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'xml'])

13
app/api/views.py

@ -2,6 +2,7 @@ import collections
import json import json
import random import random
from auto_labeling_pipeline.menu import Options
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import transaction from django.db import transaction
@ -481,3 +482,15 @@ class LabelUploadAPI(APIView):
except IntegrityError: except IntegrityError:
content = {'error': 'IntegrityError: you cannot create a label with same name or shortkey.'} content = {'error': 'IntegrityError: you cannot create a label with same name or shortkey.'}
return Response(content, status=status.HTTP_400_BAD_REQUEST) return Response(content, status=status.HTTP_400_BAD_REQUEST)
class AutoLabelingTemplateAPI(APIView):
task_mapping = {'DocumentClassification': 'TextClassification'}
permission_classes = [IsAuthenticated & IsProjectAdmin]
def get(self, request, *args, **kwargs):
project = get_object_or_404(Project, pk=self.kwargs['project_id'])
task = self.task_mapping.get(project.project_type, project.project_type)
options = Options.filter_by_task(task_name=task)
option_names = [o.name for o in options]
return Response(option_names, status=status.HTTP_200_OK)
Loading…
Cancel
Save