diff --git a/doccano/app/server/models.py b/doccano/app/server/models.py index 0a44dbc8..4f74b858 100644 --- a/doccano/app/server/models.py +++ b/doccano/app/server/models.py @@ -23,6 +23,9 @@ class Label(models.Model): 'text': self.text, 'shortcut': self.shortcut} + def __str__(self): + return self.text + class Document(models.Model): text = models.TextField() @@ -32,6 +35,9 @@ class Document(models.Model): return {'id': self.id, 'text': self.text} + def __str__(self): + return self.text[:50] + class Annotation(models.Model): prob = models.FloatField(blank=True, null=True) @@ -41,7 +47,7 @@ class Annotation(models.Model): def as_dict(self): return {'id': self.id, - 'data_id': self.data.id, - 'label_id': self.label.id, + 'doc': self.data.as_dict(), + 'label': self.label.as_dict(), 'prob': self.prob, 'manual': self.manual} diff --git a/doccano/app/server/templates/project_admin.html b/doccano/app/server/templates/project_admin.html index 57f7fa15..3cc6a6d8 100644 --- a/doccano/app/server/templates/project_admin.html +++ b/doccano/app/server/templates/project_admin.html @@ -106,6 +106,14 @@ +
+

Data Download

+ + + + + Download + diff --git a/doccano/app/server/urls.py b/doccano/app/server/urls.py index 52f0b0c4..5d91e66c 100644 --- a/doccano/app/server/urls.py +++ b/doccano/app/server/urls.py @@ -1,12 +1,13 @@ from django.urls import path from .views import AnnotationView, AnnotationAPIView, ProgressAPI, SearchAPI, InboxView -from .views import ProjectListView, ProjectAdminView, RawDataAPI, LabelAPI +from .views import ProjectListView, ProjectAdminView, RawDataAPI, LabelAPI, DataDownloadAPI urlpatterns = [ path('', ProjectListView.as_view(), name='project-list'), path('/admin', ProjectAdminView.as_view(), name='project-admin'), path('/', AnnotationView.as_view(), name='annotation'), + path('/download', DataDownloadAPI.as_view(), name='download'), path('/inbox', InboxView.as_view(), name='inbox'), path('/apis/data', AnnotationAPIView.as_view()), path('/apis/raw_data', RawDataAPI.as_view(), name='data_api'), diff --git a/doccano/app/server/views.py b/doccano/app/server/views.py index 68a7676c..4cba995b 100644 --- a/doccano/app/server/views.py +++ b/doccano/app/server/views.py @@ -1,6 +1,6 @@ import json -from django.http import JsonResponse +from django.http import JsonResponse, HttpResponse from django.shortcuts import render from django.views import View from django.views.generic.list import ListView @@ -174,3 +174,15 @@ class ProjectAdminView(DetailView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) return context + + +class DataDownloadAPI(View): + + def get(self, request, *args, **kwargs): + # j = {'hoge': 'fuga'} + annotated_docs = [a.as_dict() for a in Annotation.objects.filter(manual=True)] + json_str = json.dumps(annotated_docs) + response = HttpResponse(json_str, content_type='application/json') + response['Content-Disposition'] = 'attachment; filename=annotation_data.json' + + return response