Browse Source

Add django project

pull/10/head
Hironsan 7 years ago
parent
commit
2ae62d5451
18 changed files with 443 additions and 1 deletions
  1. 0
      doccano/app/app/__init__.py
  2. 124
      doccano/app/app/settings.py
  3. 24
      doccano/app/app/urls.py
  4. 16
      doccano/app/app/wsgi.py
  5. 15
      doccano/app/manage.py
  6. 0
      doccano/app/server/__init__.py
  7. 3
      doccano/app/server/admin.py
  8. 5
      doccano/app/server/apps.py
  9. 0
      doccano/app/server/migrations/__init__.py
  10. 3
      doccano/app/server/models.py
  11. 10
      doccano/app/server/static/bulma.js
  12. 68
      doccano/app/server/static/forum.css
  13. BIN
      doccano/app/server/static/images/logo.png
  14. 32
      doccano/app/server/static/main.js
  15. 129
      doccano/app/server/templates/annotation.html
  16. 3
      doccano/app/server/tests.py
  17. 10
      doccano/app/server/views.py
  18. 2
      doccano/server/run_server.py

0
doccano/app/app/__init__.py

124
doccano/app/app/settings.py

@ -0,0 +1,124 @@
"""
Django settings for app project.
Generated by 'django-admin startproject' using Django 2.0.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'v8sk33sy82!uw3ty=!jjv5vp7=s2phrzw(m(hrn^f7e_#1h2al'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'app.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'server/templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'server/static'),
]
WSGI_APPLICATION = 'app.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'

24
doccano/app/app/urls.py

@ -0,0 +1,24 @@
"""app URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from doccano.app.server.views import AnnotationView
urlpatterns = [
path('annotation/', AnnotationView.as_view()),
path('admin/', admin.site.urls),
]

16
doccano/app/app/wsgi.py

@ -0,0 +1,16 @@
"""
WSGI config for app project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
application = get_wsgi_application()

15
doccano/app/manage.py

@ -0,0 +1,15 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

0
doccano/app/server/__init__.py

3
doccano/app/server/admin.py

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
doccano/app/server/apps.py

@ -0,0 +1,5 @@
from django.apps import AppConfig
class ServerConfig(AppConfig):
name = 'server'

0
doccano/app/server/migrations/__init__.py

3
doccano/app/server/models.py

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

10
doccano/app/server/static/bulma.js

@ -0,0 +1,10 @@
// The following code is based off a toggle menu by @Bradcomp
// source: https://gist.github.com/Bradcomp/a9ef2ef322a8e8017443b626208999c1
(function() {
var burger = document.querySelector('.burger');
var menu = document.querySelector('#'+burger.dataset.target);
burger.addEventListener('click', function() {
burger.classList.toggle('is-active');
menu.classList.toggle('is-active');
});
})();

68
doccano/app/server/static/forum.css

@ -0,0 +1,68 @@
html,body {
font-family: 'Open Sans', serif;
background: #F9F9F9;
}
footer {
background-color: #F2F6FA !important;
}
.topNav {
border-top: 5px solid #3498DB;
}
.topNav .container {
border-bottom: 1px solid #E6EAEE;
}
.container .columns {
margin: 2rem 0;
}
.navbar-menu .navbar-item {
padding: 0 2rem;
}
aside.menu {
padding-top: 3rem;
}
aside.menu .menu-list {
line-height: 1.5;
}
aside.menu .menu-label {
padding-left: 10px;
font-weight: 700;
}
.button.is-primary.is-alt {
background: #00c6ff;
background: -webkit-linear-gradient(to bottom, #0072ff, #00c6ff);
background: linear-gradient(to bottom, #0072ff, #00c6ff);
font-weight: 700;
font-size: 14px;
height: 3rem;
line-height: 2.8;
}
.media-left img {
border-radius: 50%;
}
.media-content p {
font-size: 14px;
line-height: 2.3;
font-weight: 700;
color: #8F99A3;
}
article.post {
margin: 1rem;
padding-bottom: 1rem;
border-bottom: 1px solid #E6EAEE;
}
article.post:last-child {
padding-bottom: 0;
border-bottom: none;
}
.menu-list li{
padding: 5px;
}
.tag:not(body).is-grey {
background-color: #eee;
color: #666;
}
p {
font-family: "游ゴシック体", YuGothic, "YuGothic M", sans-serif;
}

BIN
doccano/app/server/static/images/logo.png

Before After
Width: 200  |  Height: 200  |  Size: 17 KiB

32
doccano/app/server/static/main.js

@ -0,0 +1,32 @@
Vue.config.debug = true;
var app4 = new Vue({
el: '#app',
delimiters: ['[[', ']]'],
data: {
cur: 2,
items: [
{"id": 10, "labels": [{"text": "Prefecture", "prob": 0.98}, {"text": "Domestic Region", "prob": 0.58}], "text": "北海道(ほっかいどう)は、日本の北部に位置する島[※ 1][※ 2]。また、同島および付随する島を管轄する地方公共団体(道)である。島としての北海道は日本列島を構成する主要4島の一つである。地方公共団体としての北海道は47都道府県中唯一の「道」で、道庁所在地は札幌市。"},
{"id": 11, "labels": [{"text": "Person", "prob": 0.98}], "text": "安倍 晋三(あべ しんぞう、1954年(昭和29年)9月21日 - )は、日本の政治家。自由民主党所属の衆議院議員(9期)、第90代・第96代・第97代・第98代内閣総理大臣、第21代・第25代自由民主党総裁。"},
{"id": 12, "labels": [{"text": "Country", "prob": 0.98}, {"text": "Continental Region", "prob": 0.58}], "text": "アメリカ合衆国(アメリカがっしゅうこく、英語: United States of America)、通称アメリカ、米国(べいこく)は、50の州および連邦区から成る連邦共和国である[6][7]。アメリカ本土の48州およびワシントンD.C.は、カナダとメキシコの間の北アメリカ中央に位置する。アラスカ州は北アメリカ北西部の角に位置し、東ではカナダと、西ではベーリング海峡をはさんでロシアと国境を接している。ハワイ州は中部太平洋における島嶼群である。同国は、太平洋およびカリブに5つの有人の海外領土および9つの無人の海外領土を有する。985万平方キロメートル (km2) の総面積は世界第3位または第4位、3億1千7百万人の人口は世界第3位である。同国は世界で最も民族的に多様かつ多文化な国の1つであり、これは多くの国からの大規模な移住の産物とされている[8]。また同国の広大な国土における地理および気候も極めて多様であり、多種多様な野生生物が存在する。"},
],
labels: [
'Location', 'Organization', 'Person'
],
guideline: 'annotation text'
},
methods: {
addLabel: function (label) {
this.items[this.cur]['labels'].push({"text": label, "prob":null})
},
deleteLabel: function (index) {
this.items[this.cur]['labels'].splice(index, 1)
},
nextPage: function () {
this.cur += 1
},
prevPage: function () {
this.cur -= 1
}
}
})

129
doccano/app/server/templates/annotation.html

@ -0,0 +1,129 @@
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Forum - Free Bulma template</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">
<!-- Bulma Version 0.6.2-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css" integrity="sha256-2k1KVsNPRXxZOsXQ8aqcZ9GOOwmJTMoOB5o5Qp1d6/s=" crossorigin="anonymous" />
<link rel="stylesheet" type="text/css" href="{% static 'forum.css' %}">
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
</head>
<body>
<nav class="navbar is-white">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item" href="../">
<img src="{% static 'images/logo.png' %}" width="40" height="48">doccano
</a>
</div>
<div id="topNav" class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item">
<div class="field is-grouped">
<p class="control">
<a class="button is-small">
<span class="icon">
<i class="fa fa-user-plus"></i>
</span>
<span>
Register
</span>
</a>
</p>
<p class="control">
<a class="button is-small is-primary is-outlined">
<span class="icon">
<i class="fa fa-user"></i>
</span>
<span>Login</span>
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</nav>
<section class="container" id="app">
<div class="columns">
<div class="column is-8">
<div class="box content">
<div class="tabs is-right">
<ul>
<li class="is-active"><a>Document</a></li>
<li><a>Guidelilne</a></li>
</ul>
</div>
<article class="post">
<h4>
<div class="field is-grouped is-grouped-multiline">
<!--<div class="control" v-for="label in items[cur].labels">-->
<div class="control" v-for="(label, index) in items[cur].labels">
<div class="tags has-addons">
<span class="tag is-grey">
<button class="delete is-small" v-on:click="deleteLabel(index)"></button>
<!--Country-->
[[label.text]]
</span>
<span class="tag is-primary" v-if="label.prob">[[label.prob]]<!--0.98--></span>
</div>
</div>
</div>
</h4>
<div class="media">
<div class="media-content">
<div class="content">
<p>
[[items[cur].text]]
</p>
</div>
</div>
</div>
</article>
</div>
</div>
<div class="column is-4">
<div class="box content">
<div class="tabs is-right">
<ul>
<li class="is-active"><a>Labeling</a></li>
<li><a>History</a></li>
</ul>
</div>
<div class="control">
<a class="button is-link" v-on:click="prevPage"><i class="fa fa-chevron-left"></i></a>
<a class="button is-link" v-on:click="nextPage"><i class="fa fa-chevron-right"></i></a>
</div>
<a class="button is-primary is-block" href="#">Learn & Classify</a>
<aside class="menu">
<p class="menu-label">
Tags
</p>
<div class="tags">
<a class="tag is-grey" v-for="label in labels" v-on:click="addLabel(label)">[[label]]</a>
</div>
</aside>
</div>
</div>
</div>
</section>
<script async type="text/javascript" src="{% static 'bulma.js' %}"></script>
<script type="text/javascript" src="{% static 'main.js' %}">
</script>
</body>
</html>

3
doccano/app/server/tests.py

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

10
doccano/app/server/views.py

@ -0,0 +1,10 @@
from django.shortcuts import render
from django.views import View
class AnnotationView(View):
template_name = 'annotation.html'
def get(self, request, *args, **kwargs):
# form = self.form_class(initial=self.initial)
return render(request, self.template_name)

2
doccano/server/run_server.py

@ -8,7 +8,7 @@ from tornado.web import url
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render('index2.html')
self.render('annotation.html')
def post(self):
pass

Loading…
Cancel
Save