first commit
This commit is contained in:
0
code/fuadmin/__init__.py
Normal file
0
code/fuadmin/__init__.py
Normal file
29
code/fuadmin/api.py
Normal file
29
code/fuadmin/api.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2022/5/9 23:15
|
||||
# @Author : 臧成龙
|
||||
# @FileName: api.py
|
||||
# @Software: PyCharm
|
||||
from demo.router import demo_router
|
||||
from system.router import system_router
|
||||
from utils.fu_auth import GlobalAuth
|
||||
from utils.fu_ninja import FuNinjaAPI
|
||||
from generator.router import generator_router
|
||||
|
||||
|
||||
# api = FuNinjaAPI(auth=GlobalAuth())
|
||||
api = FuNinjaAPI() # 移除auth参数
|
||||
|
||||
|
||||
# 统一处理server异常
|
||||
@api.exception_handler(Exception)
|
||||
def a(request, exc):
|
||||
|
||||
if hasattr(exc, 'errno'):
|
||||
return api.create_response(request, data=[], msg=str(exc), code=exc.errno)
|
||||
else:
|
||||
return api.create_response(request, data=[], msg=str(exc), code=500)
|
||||
|
||||
|
||||
api.add_router('/system/', system_router)
|
||||
api.add_router('/demo/', demo_router)
|
||||
api.add_router('/generator/', generator_router)
|
||||
16
code/fuadmin/asgi.py
Normal file
16
code/fuadmin/asgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for fuadmin project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fuadmin.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
14
code/fuadmin/celery.py
Normal file
14
code/fuadmin/celery.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import os
|
||||
|
||||
from celery import Celery, platforms
|
||||
from django.conf import settings
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', "fuadmin.settings")
|
||||
|
||||
# app = Celery(f"application")
|
||||
app = Celery(f"system")
|
||||
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
||||
# app.autodiscover_tasks()
|
||||
platforms.C_FORCE_ROOT = True
|
||||
326
code/fuadmin/settings.py
Normal file
326
code/fuadmin/settings.py
Normal file
@@ -0,0 +1,326 @@
|
||||
"""
|
||||
Django settings for fuadmin project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.0.4.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.0/ref/settings/
|
||||
"""
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
from conf.env import *
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-x4k4^#6wovi1aep8%ow!5fr%(9o#1u=+0+nzi($_j=^d*ui6g3'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = locals().get('DEBUG', True)
|
||||
ALLOWED_HOSTS = locals().get('ALLOWED_HOSTS', ['*'])
|
||||
DEMO = locals().get('DEMO', False)
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django_celery_beat',
|
||||
'django_celery_results',
|
||||
'system',
|
||||
'demo',
|
||||
'generator',
|
||||
]
|
||||
|
||||
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',
|
||||
'utils.middleware.ApiLoggingMiddleware',
|
||||
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'fuadmin.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [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 = 'fuadmin.wsgi.application'
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.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/4.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'zh-hans'
|
||||
|
||||
TIME_ZONE = 'Asia/Shanghai'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = False
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATICFILES_DIRS = [
|
||||
os.path.join(BASE_DIR, 'static'),
|
||||
]
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
AUTH_USER_MODEL = 'system.Users'
|
||||
USERNAME_FIELD = 'username'
|
||||
ALL_MODELS_OBJECTS = [] # 所有app models 对象
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
||||
# 数据库配置
|
||||
if DATABASE_TYPE == "MYSQL":
|
||||
# Mysql数据库
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.mysql",
|
||||
"HOST": DATABASE_HOST,
|
||||
"PORT": DATABASE_PORT,
|
||||
"USER": DATABASE_USER,
|
||||
"PASSWORD": DATABASE_PASSWORD,
|
||||
"NAME": DATABASE_NAME,
|
||||
}
|
||||
}
|
||||
elif DATABASE_TYPE == "SQLSERVER":
|
||||
# SqlServer数据库
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "mssql",
|
||||
"HOST": DATABASE_HOST,
|
||||
"PORT": DATABASE_PORT,
|
||||
"USER": DATABASE_USER,
|
||||
"PASSWORD": DATABASE_PASSWORD,
|
||||
"NAME": DATABASE_NAME,
|
||||
# 全局开启事务,绑定的是http请求响应整个过程
|
||||
'ATOMIC_REQUESTS': True,
|
||||
'OPTIONS': {
|
||||
'driver': 'ODBC Driver 17 for SQL Server',
|
||||
},
|
||||
}
|
||||
}
|
||||
elif DATABASE_TYPE == "POSTGRESQL":
|
||||
# POSTGRESQL
|
||||
DATABASES = {
|
||||
"default": {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
"HOST": DATABASE_HOST,
|
||||
"PORT": DATABASE_PORT,
|
||||
"USER": DATABASE_USER,
|
||||
"PASSWORD": DATABASE_PASSWORD,
|
||||
"NAME": DATABASE_NAME,
|
||||
# 全局开启事务,绑定的是http请求响应整个过程
|
||||
'ATOMIC_REQUESTS': True,
|
||||
}
|
||||
}
|
||||
else:
|
||||
# sqlite3 数据库
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
'OPTIONS': {
|
||||
'timeout': 20,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
# 缓存配置
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": f'{REDIS_URL}/1',
|
||||
"TIMEOUT": None,
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# # ================================================= #
|
||||
# # ********************* 日志配置 ******************* #
|
||||
# # ================================================= #
|
||||
# # log 配置部分BEGIN #
|
||||
SERVER_LOGS_FILE = os.path.join(BASE_DIR, "logs", "server.log")
|
||||
ERROR_LOGS_FILE = os.path.join(BASE_DIR, "logs", "error.log")
|
||||
LOGS_FILE = os.path.join(BASE_DIR, "logs")
|
||||
if not os.path.exists(os.path.join(BASE_DIR, "logs")):
|
||||
os.makedirs(os.path.join(BASE_DIR, "logs"))
|
||||
|
||||
# 格式:[2020-04-22 23:33:01][micoservice.apps.ready():16] [INFO] 这是一条日志:
|
||||
# 格式:[日期][模块.函数名称():行号] [级别] 信息
|
||||
STANDARD_LOG_FORMAT = (
|
||||
"[%(asctime)s][%(name)s.%(funcName)s():%(lineno)d] [%(levelname)s] %(message)s"
|
||||
)
|
||||
CONSOLE_LOG_FORMAT = (
|
||||
"[%(asctime)s][%(name)s.%(funcName)s():%(lineno)d] [%(levelname)s] %(message)s"
|
||||
)
|
||||
LOGGING = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"standard": {"format": STANDARD_LOG_FORMAT},
|
||||
"console": {
|
||||
"format": CONSOLE_LOG_FORMAT,
|
||||
"datefmt": "%Y-%m-%d %H:%M:%S",
|
||||
},
|
||||
"file": {
|
||||
"format": CONSOLE_LOG_FORMAT,
|
||||
"datefmt": "%Y-%m-%d %H:%M:%S",
|
||||
},
|
||||
},
|
||||
"handlers": {
|
||||
"file": {
|
||||
"level": "INFO",
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": SERVER_LOGS_FILE,
|
||||
"maxBytes": 1024 * 1024 * 100, # 100 MB
|
||||
"backupCount": 5, # 最多备份5个
|
||||
"formatter": "standard",
|
||||
"encoding": "utf-8",
|
||||
},
|
||||
"error": {
|
||||
"level": "ERROR",
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"filename": ERROR_LOGS_FILE,
|
||||
"maxBytes": 1024 * 1024 * 100, # 100 MB
|
||||
"backupCount": 3, # 最多备份3个
|
||||
"formatter": "standard",
|
||||
"encoding": "utf-8",
|
||||
},
|
||||
"console": {
|
||||
"level": "INFO",
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "console",
|
||||
},
|
||||
|
||||
},
|
||||
"loggers": {
|
||||
"": {
|
||||
"handlers": ["console", "error", "file"],
|
||||
"level": "INFO",
|
||||
},
|
||||
"django": {
|
||||
"handlers": ["console", "error", "file"],
|
||||
"level": "INFO",
|
||||
"propagate": False,
|
||||
},
|
||||
'django.db.backends': {
|
||||
'handlers': ["console", "error", "file"],
|
||||
'propagate': False,
|
||||
'level': "INFO"
|
||||
},
|
||||
"uvicorn.error": {
|
||||
"level": "INFO",
|
||||
"handlers": ["console", "error", "file"],
|
||||
},
|
||||
"uvicorn.access": {
|
||||
"handlers": ["console", "error", "file"],
|
||||
"level": "INFO"
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# celery 配置
|
||||
CELERY_BROKER_URL = f'{REDIS_URL}/2'
|
||||
DJANGO_CELERY_BEAT_TZ_AWARE = False
|
||||
CELERY_ENABLE_UTC = False
|
||||
CELERY_WORKER_CONCURRENCY = 2 # 并发数
|
||||
CELERY_MAX_TASKS_PER_CHILD = 5 # 每个worker最多执行5个任务便自我销毁释放内存
|
||||
CELERY_TIMEZONE = TIME_ZONE # celery 时区问题
|
||||
CELERY_RESULT_BACKEND = 'django-db' # celery结果存储到数据库中
|
||||
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler' # Backend数据库
|
||||
|
||||
# token 有效时间 时 分 秒
|
||||
TOKEN_LIFETIME = 12 * 60 * 60
|
||||
# TOKEN_LIFETIME = 50
|
||||
|
||||
# 接口白名单,不需要授权直接访问
|
||||
WHITE_LIST = ['/api/system/userinfo', '/api/system/permCode', '/api/system/menu/route/tree', '/api/system/user/*',
|
||||
'/api/system/user/set/repassword']
|
||||
|
||||
# 接口日志记录
|
||||
API_LOG_ENABLE = True
|
||||
API_LOG_METHODS = ['POST', 'GET', 'DELETE', 'PUT']
|
||||
API_MODEL_MAP = {}
|
||||
|
||||
# 初始化需要执行的列表,用来初始化后执行
|
||||
INITIALIZE_RESET_LIST = []
|
||||
|
||||
|
||||
|
||||
# vdes监听器配置
|
||||
# VDES_MONITOR_HOST = '192.168.2.183'
|
||||
# VDES_MONITOR_PORT = 10
|
||||
# VDES_MONITOR_HOST = '172.16.1.59'
|
||||
# VDES_MONITOR_PORT = 8081
|
||||
VDES_MONITOR_HOST = 'localhost'
|
||||
VDES_MONITOR_PORT = 10
|
||||
|
||||
VDES_BUFFER_SIZE = 65536 # 接收缓冲区大小
|
||||
|
||||
# ais船只信息配置
|
||||
OWN_SHIP_MMSI = '413323670'
|
||||
OWN_SHIP_NAME = '湃星一号'
|
||||
OWN_SHIP_TYPE = '货船'
|
||||
RADIUS_NM = 150.0 #显示周边多少海里范围的船只
|
||||
|
||||
29
code/fuadmin/urls.py
Normal file
29
code/fuadmin/urls.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""fuadmin URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.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 django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from .api import api
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/', api.urls),
|
||||
]
|
||||
|
||||
# 在开发环境中添加静态文件 URL 配置
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
16
code/fuadmin/wsgi.py
Normal file
16
code/fuadmin/wsgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for fuadmin 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/4.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fuadmin.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user