Browse Source

Update url

pull/10/head
Hironsan 6 years ago
parent
commit
f70a8b079a
3 changed files with 6 additions and 20 deletions
  1. BIN
      app/db.sqlite3
  2. 9
      app/server/urls.py
  3. 17
      app/server/views.py

BIN
app/db.sqlite3

9
app/server/urls.py

@ -2,7 +2,7 @@ from django.urls import path
from .views import IndexView
from .views import ProjectView, DatasetView, DatasetUpload
from .views import ProjectsView, ProjectAdminView, RawDataAPI, DataDownload
from .views import ProjectsView, ProjectAdminView, DataDownload
from rest_framework import routers
from .views import ProjectViewSet
from .views import ProjectLabelsAPI, ProjectLabelAPI, ProjectDocsAPI, AnnotationsAPI, AnnotationAPI
@ -20,10 +20,9 @@ urlpatterns = [
path('api/projects/<int:project_id>/docs/<int:doc_id>/annotations/', AnnotationsAPI.as_view(), name='annotations'),
path('api/projects/<int:project_id>/docs/<int:doc_id>/annotations/<int:annotation_id>', AnnotationAPI.as_view(), name='ann'),
path('projects/', ProjectsView.as_view(), name='projects'),
path('projects/<int:pk>/admin', ProjectAdminView.as_view(), name='project-admin'),
path('projects/<int:project_id>/admin', ProjectAdminView.as_view(), name='project-admin'),
path('projects/<int:project_id>/download', DataDownload.as_view(), name='download'),
path('projects/<int:project_id>/', ProjectView.as_view(), name='annotation'),
path('projects/<int:pk>/apis/raw_data', RawDataAPI.as_view(), name='data_api'),
path('projects/<int:pk>/docs/', DatasetView.as_view(), name='dataset'),
path('projects/<int:pk>/docs/create', DatasetUpload.as_view(), name='dataset-upload'),
path('projects/<int:project_id>/docs/', DatasetView.as_view(), name='dataset'),
path('projects/<int:project_id>/docs/create', DatasetUpload.as_view(), name='dataset-upload'),
]

17
app/server/views.py

@ -55,7 +55,7 @@ class DatasetView(LoginRequiredMixin, ListView):
paginate_by = 5
def get_queryset(self):
project_id = self.kwargs['pk']
project_id = self.kwargs['project_id']
project = get_object_or_404(Project, pk=project_id)
return project.documents.all()
@ -67,7 +67,7 @@ class DatasetUpload(LoginRequiredMixin, View):
return render(request, 'admin/dataset_upload.html')
def post(self, request, *args, **kwargs):
project = get_object_or_404(Project, pk=kwargs.get('pk'))
project = get_object_or_404(Project, pk=kwargs.get('project_id'))
try:
form_data = TextIOWrapper(request.FILES['csv_file'].file, encoding='utf-8')
reader = csv.reader(form_data)
@ -80,19 +80,6 @@ class DatasetUpload(LoginRequiredMixin, View):
return HttpResponseRedirect(reverse('dataset-upload', args=[project.id]))
class RawDataAPI(View):
def post(self, request, *args, **kwargs):
"""Upload data."""
f = request.FILES['file']
content = ''.join(chunk.decode('utf-8') for chunk in f.chunks())
for line in content.split('\n'):
j = json.loads(line)
Document(text=j['text']).save()
return JsonResponse({'status': 'ok'})
class DataDownload(View):
def get(self, request, *args, **kwargs):

Loading…
Cancel
Save