Commit 9b5b48dd authored by ibuler's avatar ibuler

[Update] 修改settings conf配置

parent 75fb37d2
...@@ -273,6 +273,19 @@ class Config(dict): ...@@ -273,6 +273,19 @@ class Config(dict):
if default_value is None: if default_value is None:
return v return v
tp = type(default_value) tp = type(default_value)
# 对bool特殊处理
if tp is bool and isinstance(v, str):
if v in ("true", "True", "1"):
return True
else:
return False
if tp in [list, dict] and isinstance(v, str):
try:
v = json.loads(v)
return v
except json.JSONDecodeError:
return v
try: try:
v = tp(v) v = tp(v)
except Exception: except Exception:
...@@ -289,14 +302,10 @@ class Config(dict): ...@@ -289,14 +302,10 @@ class Config(dict):
except KeyError: except KeyError:
value = None value = None
if value is not None: if value is not None:
return self.convert_type(item, value) return value
# 其次从环境变量来 # 其次从环境变量来
value = os.environ.get(item, None) value = os.environ.get(item, None)
if value is not None: if value is not None:
if value.lower() == 'false':
value = False
elif value.lower() == 'true':
value = True
return self.convert_type(item, value) return self.convert_type(item, value)
return self.defaults.get(item) return self.defaults.get(item)
...@@ -362,6 +371,7 @@ defaults = { ...@@ -362,6 +371,7 @@ defaults = {
'HTTP_LISTEN_PORT': 8080, 'HTTP_LISTEN_PORT': 8080,
'LOGIN_LOG_KEEP_DAYS': 90, 'LOGIN_LOG_KEEP_DAYS': 90,
'ASSETS_PERM_CACHE_TIME': 3600, 'ASSETS_PERM_CACHE_TIME': 3600,
} }
......
...@@ -371,6 +371,8 @@ REST_FRAMEWORK = { ...@@ -371,6 +371,8 @@ REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': ( 'DEFAULT_PARSER_CLASSES': (
'rest_framework.parsers.JSONParser', 'rest_framework.parsers.JSONParser',
'rest_framework.parsers.FormParser', 'rest_framework.parsers.FormParser',
'rest_framework.parsers.MultiPartParser',
'rest_framework.parsers.FileUploadParser',
'common.parsers.JMSCSVParser' 'common.parsers.JMSCSVParser'
), ),
'DEFAULT_AUTHENTICATION_CLASSES': ( 'DEFAULT_AUTHENTICATION_CLASSES': (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment