diff --git a/doccano/app/db.sqlite3 b/doccano/app/db.sqlite3 index f0fca6da..f4c2b159 100644 Binary files a/doccano/app/db.sqlite3 and b/doccano/app/db.sqlite3 differ diff --git a/doccano/app/server/admin.py b/doccano/app/server/admin.py index cd1984a0..1cf1bb1a 100644 --- a/doccano/app/server/admin.py +++ b/doccano/app/server/admin.py @@ -1,7 +1,8 @@ from django.contrib import admin -from .models import Annotation, Label, RawData +from .models import Annotation, Label, RawData, Project admin.site.register(Annotation) admin.site.register(Label) admin.site.register(RawData) +admin.site.register(Project) diff --git a/doccano/app/server/models.py b/doccano/app/server/models.py index 3ba9899d..622a6d2f 100644 --- a/doccano/app/server/models.py +++ b/doccano/app/server/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.contrib.auth.models import User class Label(models.Model): @@ -33,13 +34,12 @@ class Annotation(models.Model): 'manual': self.manual} -class User(models.Model): - name = models.CharField(max_length=100) - email = models.EmailField() - password = models.CharField(max_length=32) - # password = forms.CharField(max_length=32, widget=forms.PasswordInput) - - class Project(models.Model): name = models.CharField(max_length=100) - # users = models.ManyToManyField(User) + description = models.TextField() + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + users = models.ManyToManyField(User) + + def __str__(self): + return self.name diff --git a/doccano/app/server/templates/project_list.html b/doccano/app/server/templates/project_list.html new file mode 100644 index 00000000..94d8873c --- /dev/null +++ b/doccano/app/server/templates/project_list.html @@ -0,0 +1,74 @@ +{% extends "base.html" %} +{% load static %} +{% block content %} +
+
+ +
+
+ {% for project in object_list %} +
+

{{ project.name }}

+
+
+

+ +

+
+
+
+

{{ project.description|truncatechars:200 }}

+

+ @jsmith created at {{ project.created_at|date }}   + Question +

+
+
+
+ + 1 +
+
+
+ {% empty %} + No projects yet. + {% endfor %} +
+
+ + +
+ New Project + +
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/doccano/app/server/tests.py b/doccano/app/server/tests.py index 7ce503c2..daee335f 100644 --- a/doccano/app/server/tests.py +++ b/doccano/app/server/tests.py @@ -1,3 +1,10 @@ from django.test import TestCase -# Create your tests here. +from .models import Project + + +class ProjectModelTest(TestCase): + + def test_string_representation(self): + project = Project(name='my project', description='my description') + self.assertEqual(str(project), project.name) diff --git a/doccano/app/server/urls.py b/doccano/app/server/urls.py index 03738dbe..11aa055c 100644 --- a/doccano/app/server/urls.py +++ b/doccano/app/server/urls.py @@ -1,8 +1,9 @@ from django.urls import path -from .views import AnnotationView, AnnotationAPIView, MetaInfoAPI, SearchAPI +from .views import AnnotationView, AnnotationAPIView, MetaInfoAPI, SearchAPI, ProjectListView urlpatterns = [ + path('', ProjectListView.as_view(), name='project-list'), path('/docs', AnnotationView.as_view()), path('/apis/data', AnnotationAPIView.as_view()), path('/apis/label', MetaInfoAPI.as_view()), diff --git a/doccano/app/server/views.py b/doccano/app/server/views.py index b34e7a6a..7fd5538b 100644 --- a/doccano/app/server/views.py +++ b/doccano/app/server/views.py @@ -3,8 +3,9 @@ import json from django.http import JsonResponse from django.shortcuts import render from django.views import View +from django.views.generic.list import ListView -from .models import Annotation, Label, RawData +from .models import Annotation, Label, RawData, Project class AnnotationView(View): @@ -72,3 +73,14 @@ class SearchAPI(View): # Annotation.objects.select_related('data').all().filter(data__text__contains=keyword) return JsonResponse({'data': docs}) + + +class ProjectListView(ListView): + + model = Project + paginate_by = 100 # if pagination is desired + template_name = 'project_list.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + return context