refect: settings里增加配置

This commit is contained in:
caoqianming 2023-09-26 14:30:42 +08:00
parent 515d0b5c17
commit 847cdc76a4
1 changed files with 8 additions and 3 deletions

View File

@ -13,17 +13,19 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
from datetime import datetime, timedelta from datetime import datetime, timedelta
import os import os
import json import json
import sys
from . import conf from . import conf
from django.core.cache import cache from django.core.cache import cache
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
SYS_JSON_PATH = os.path.join(BASE_DIR, 'server/conf.json') SYS_JSON_PATH = os.path.join(BASE_DIR, 'server/conf.json')
def get_sysconfig(reload=False): def get_sysconfig(reload=False):
config = cache.get('system_config', None) config = cache.get('system_config', None)
if config is None or reload: if config is None or reload:
@ -36,6 +38,7 @@ def get_sysconfig(reload=False):
return config return config
return config return config
def update_dict(dict1, dict2): def update_dict(dict1, dict2):
for key, value in dict2.items(): for key, value in dict2.items():
if key == 'apk_file': # apk_file拷贝到固定位置 if key == 'apk_file': # apk_file拷贝到固定位置
@ -46,16 +49,18 @@ def update_dict(dict1, dict2):
else: else:
dict1[key] = value dict1[key] = value
def update_sysconfig(new_dict): def update_sysconfig(new_dict):
config = get_sysconfig() config = get_sysconfig()
update_dict(config, new_dict) update_dict(config, new_dict)
with open(SYS_JSON_PATH, 'wb') as f: with open(SYS_JSON_PATH, 'wb') as f:
f.write(json.dumps(config, indent=4, ensure_ascii=False).encode('utf-8')) f.write(json.dumps(config, indent=4, ensure_ascii=False).encode('utf-8'))
cache.set('system_config', config) cache.set('system_config', config)
# 重启时需要reload 不能这样操作, 会使缓存有问题,我也不知道为什么 # 重启时需要reload 不能这样操作, 会使缓存有问题,我也不知道为什么
# get_sysconfig(reload=True) # get_sysconfig(reload=True)
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = conf.SECRET_KEY SECRET_KEY = conf.SECRET_KEY
@ -206,7 +211,7 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# 人脸库配置 # 人脸库配置
# 如果地址不存在,则自动创建/现在直接存库可不用 # 如果地址不存在,则自动创建/现在直接存库可不用
FACE_PATH= os.path.join(BASE_DIR, 'media/face') FACE_PATH = os.path.join(BASE_DIR, 'media/face')
if not os.path.exists(FACE_PATH): if not os.path.exists(FACE_PATH):
os.makedirs(FACE_PATH) os.makedirs(FACE_PATH)