Browse Source

Add project list page

pull/10/head
Hironsan 6 years ago
parent
commit
0d83f4bf66
7 changed files with 107 additions and 12 deletions
  1. BIN
      doccano/app/db.sqlite3
  2. 3
      doccano/app/server/admin.py
  3. 16
      doccano/app/server/models.py
  4. 74
      doccano/app/server/templates/project_list.html
  5. 9
      doccano/app/server/tests.py
  6. 3
      doccano/app/server/urls.py
  7. 14
      doccano/app/server/views.py

BIN
doccano/app/db.sqlite3

3
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)

16
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

74
doccano/app/server/templates/project_list.html

@ -0,0 +1,74 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<section class="container" id="root">
<div class="columns">
<div class="column is-9">
<div class="box content">
{% for project in object_list %}
<article class="post">
<h4>{{ project.name }}</h4>
<div class="media">
<div class="media-left">
<p class="image is-32x32">
<img src="http://bulma.io/images/placeholders/128x128.png">
</p>
</div>
<div class="media-content">
<div class="content">
<p>{{ project.description|truncatechars:200 }}</p>
<p>
<a href="#">@jsmith</a> created at {{ project.created_at|date }} &nbsp;
<span class="tag">Question</span>
</p>
</div>
</div>
<div class="media-right">
<span class="has-text-grey-light">
<i class="fa fa-comments"></i> 1</span>
</div>
</div>
</article>
{% empty %}
No projects yet.
{% endfor %}
</div>
</div>
<div class="column is-3">
<a class="button is-primary is-block is-alt is-large" href="#">New Project</a>
<aside class="menu">
<p class="menu-label">
Tags
</p>
<ul class="menu-list">
<li>
<span class="tag is-primary is-medium ">Dashboard</span>
</li>
<li>
<span class="tag is-link is-medium ">Customers</span>
</li>
<li>
<span class="tag is-light is-danger is-medium ">Authentication</span>
</li>
<li>
<span class="tag is-dark is-medium ">Payments</span>
</li>
<li>
<span class="tag is-success is-medium ">Transfers</span>
</li>
<li>
<span class="tag is-warning is-medium ">Balance</span>
</li>
<li>
<span class="tag is-medium ">Question</span>
</li>
</ul>
</aside>
</div>
</div>
</section>
{% endblock %}

9
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)

3
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('<int:project_id>/docs', AnnotationView.as_view()),
path('<int:project_id>/apis/data', AnnotationAPIView.as_view()),
path('<int:project_id>/apis/label', MetaInfoAPI.as_view()),

14
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
Loading…
Cancel
Save