From 7da1f46a2480de3e04b8b407a703eef911842d34 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 31 May 2018 14:46:16 +0900 Subject: [PATCH] Add label API --- doccano/app/server/views.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doccano/app/server/views.py b/doccano/app/server/views.py index 870521b6..3992fc61 100644 --- a/doccano/app/server/views.py +++ b/doccano/app/server/views.py @@ -76,6 +76,31 @@ class SearchAPI(View): return JsonResponse({'data': docs}) +class LabelAPI(View): + + def get(self, request, *args, **kwargs): + """Get labels.""" + labels = Label.objects.all() + labels = [label.as_dict() for label in labels] + + return JsonResponse({'labels': labels}) + + def post(self, request, *args, **kwargs): + """Create labels.""" + Label().save() + + return JsonResponse({'status': 'ok'}) + + def put(self, request, *args, **kwargs): + """Update labels.""" + label = Label.objects.get(id=1) + label.text = '' + label.shortcut = '' + label.save() + + return JsonResponse({'status': 'ok'}) + + class ProjectListView(ListView): model = Project