Init project structure

pull/530/head
ibuler 2016-08-09 00:43:11 +08:00
parent ba215335bf
commit b5c159c967
49 changed files with 410 additions and 0 deletions

0
LICENSE Normal file
View File

5
README.md Normal file
View File

@ -0,0 +1,5 @@
## 文档
[参考](https://code.simcu.com/jumpserver/jumpserver/tree/master/docs)

0
config-example.py Normal file
View File

View File

View File

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

7
dashboard/assets/apps.py Normal file
View File

@ -0,0 +1,7 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class AssetsConfig(AppConfig):
name = 'assets'

View File

View File

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

View File

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

View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

View File

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

7
dashboard/audits/apps.py Normal file
View File

@ -0,0 +1,7 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class AuditsConfig(AppConfig):
name = 'audits'

View File

View File

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

View File

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

View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

View File

@ -0,0 +1,127 @@
"""
Django settings for jumpserver project.
Generated by 'django-admin startproject' using Django 1.10.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/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/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '2vym+ky!997d5kkcc64mnz06y1mmui3lut#(^wd=%s_qj$1%xv'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'users.apps.AppConfig',
'assets.apps.AppConfig',
'perms.apps.AppConfig',
'audits.apps.AppConfig',
# '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 = 'jumpserver.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, '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',
],
},
},
]
WSGI_APPLICATION = 'jumpserver.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/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/1.10/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/1.10/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)

View File

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

View File

@ -0,0 +1,16 @@
"""
WSGI config for jumpserver 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/1.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings")
application = get_wsgi_application()

22
dashboard/manage.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
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?"
)
raise
execute_from_command_line(sys.argv)

View File

3
dashboard/perms/admin.py Normal file
View File

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

7
dashboard/perms/apps.py Normal file
View File

@ -0,0 +1,7 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class PermsConfig(AppConfig):
name = 'perms'

View File

View File

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

3
dashboard/perms/tests.py Normal file
View File

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

3
dashboard/perms/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

3
dashboard/users/admin.py Normal file
View File

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

7
dashboard/users/apps.py Normal file
View File

@ -0,0 +1,7 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'

View File

View File

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

View File

3
dashboard/users/tests.py Normal file
View File

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

3
dashboard/users/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

4
docs/README.md Normal file
View File

@ -0,0 +1,4 @@
## 代码规范
[参考](https://code.simcu.com/jumpserver/jumpserver/blob/master/docs/code_style.md)

131
docs/code_style.md Normal file
View File

@ -0,0 +1,131 @@
# Jumpserver 项目规范Draft
## 语言框架
1. Python 2.7 由于ansible目前不支持python3
2. Django 1.10 (最新版本)
3. Terminal Websocket使用go实现
## 代码风格
1. Python方面大致的风格我们采用[pocoo的Style Guidance](http://www.pocoo.org/internal/styleguide/),但是有些细节部分会尽量放开。
2. 前端部分(js, css, html),采用[Google的HTML/CSS Coding Style Guidance](https://google.github.io/styleguide/htmlcssguide.xml)以及[JavaScript Coding Style](http://google.github.io/styleguide/javascriptguide.xml)
3. Google的Style指南还规范了各种写法不光包括Coding Format请尽量遵守但Coding Format的原则则必须遵守。
4. Go的代码风格由@Tad指定。
5. 所有人编码前请仔细阅读相应的代码风格指导规范编码的时候请严格遵循相互review代码。
## Django规范
1. 尽量使用Class Base View编程更少代码
2. 使用Django Form
3. 每个url独立命名不要硬编码同理static也是
4. 数据库表名手动指定,不要使用默认
5. 代码优雅简洁
6. 注释明确优美
7. 测试案例尽可能完整
8. 尽可能利用Django造好的轮子
关于代码风格规范一些补充说明:
### 基本的代码布局
#### 缩进
1. Python严格采用4个空格的缩进不使用tab\t任何python代码都都必须遵守此规定。
2. web部分代码(HTML, CSS, JavaScript)Node.js采用2空格缩进同样不使用tab (\t)。
之所以与Python不同是因为js中有大量回调式的写法2空格可以显著降低视觉上的负担。
#### 最大行长度
按PEP8规范Python一般限制最大80个字符, 强制遵守。
**补充说明HTML代码不受此规范约束。**
#### 长语句缩进
Python代码参考pocoo style(注: 参考Flask源码)一致。JavaScript代码参考Google的Coding Format说明。
#### 空行
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
### 语句和表达式
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
### 命名约定
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
### 文档注释(Docstring即各方法类的说明文档注释)
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
### 注释(comment)
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
## 项目骨架
## 项目骨架
说明如下:
```
.
├── assets // app目录
│ ├── admin.py
│ ├── apps.py // 新版本django app设置文件
│ ├── api.py // api文件
│ ├── __init__.py
│ ├── migrations // models Migrations版本控制目录
│ │ └── __init__.py
│ ├── models.py // 数据模型目录
│ ├── static // app下静态资源目录
│ │ └── assets // 多一层目录,防止资源重名
│ │ │ └── some_image.png
│ ├── templates // app下模板目录
│ │ └── assets // 多一层目录,防止资源重名
│ │ │ └── asset_list.html
│ ├── templatetags // 模板标签目录
│ ├── tests.py // 测试用例文件
│ ├── urls.py // urlconf文件
│ └── views.py // views文件
├── docs // 所有doc文件放到该目录
│ └── README.md
├── jumpserver // 项目设置目录
│ ├── __init__.py
│ ├── settings.py // 项目设置文件
│ ├── urls.py // 项目入口urlconf
│ └── wsgi.py
├── LICENSE
├── manage.py
├── README.md
├── static // 项目静态资源目录
└── templates // 项目模板目录
```
### Go项目
请@Tad负责补完。
### API
这里仅考虑REST API的基本情况。
#### HTTP Method
1. 读操作使用GET方法写操作使用PUT/POST/DELETE方法其中删除记录的操作使用DELETE方法。
2. 使用PUT方法实现的API必须是幂等的多次执行同样操作结果相同
3. POST则是实现非幂等的接口。
4. 一般性的CRUD操作R一般使用GET方法C使用POSTU使用PUT方法D使用DELETE方法。
#### URL
1. 每个项目的的root path后面整合的时候回指定为项目名这个不需要各项目组考虑。整合的方案可以采用Nginx来转发后面可以详细讨论
3. 一般性的增删查改(CRUD)API完全使用HTTP method加上url提供的语义url中的可变部分比如上面提到的<role_id>一般用来传递该API操作的核心实体对象的唯一ID如果有更多的参数需要提供GET方法请使用url parameter(例如:"?client_id=xxxxx&app_id=xxxxxx")PUT/POST/DELETE方法请使用请求体传递参数。
**其他具体情况具体讨论**