Fix config for bool values.
This commit is contained in:
parent
62845fa0cd
commit
b2d23de7b6
34
config.py
34
config.py
@ -6,12 +6,42 @@ BASEDIR = os.path.abspath(os.path.dirname(__file__))
|
||||
load_dotenv(os.path.join(BASEDIR, ".env"))
|
||||
|
||||
|
||||
BOOL_STR = {
|
||||
0: False,
|
||||
1: True,
|
||||
"": False,
|
||||
"0": False,
|
||||
"1": True,
|
||||
"f": False,
|
||||
"false": False,
|
||||
"o": True,
|
||||
"on": True,
|
||||
"n": False,
|
||||
"t": True,
|
||||
"true": True,
|
||||
True: True,
|
||||
"v": True,
|
||||
"vrai": True,
|
||||
"y": True,
|
||||
}
|
||||
|
||||
def to_bool(x) -> bool:
|
||||
"""Cast value to boolean.
|
||||
The value may be encoded as a string
|
||||
False are: empty, "0", "False", "f", "n".
|
||||
True: all other values, such as "1", "True", "foo", "bar"...
|
||||
Case insentive, ignore leading and trailing spaces.
|
||||
"""
|
||||
if isinstance(x, str):
|
||||
return BOOL_STR.get(x.lower().strip(), True)
|
||||
return bool(x)
|
||||
|
||||
class Config:
|
||||
"""General configuration. Mostly loaded from environment via .env"""
|
||||
|
||||
FLASK_ENV = None # # set in subclass
|
||||
SECRET_KEY = os.environ.get("SECRET_KEY") or "90e01e751977d4276a4c70d98564b425e"
|
||||
LOG_TO_STDOUT = os.environ.get("LOG_TO_STDOUT")
|
||||
# LOG_TO_STDOUT = os.environ.get("LOG_TO_STDOUT")
|
||||
LOG_LEVEL = getattr(logging, os.environ.get("LOG_LEVEL", "INFO"), "INFO")
|
||||
MAIL_SERVER = os.environ.get("MAIL_SERVER", "localhost")
|
||||
LANGUAGES = ["fr", "en"] # unused for now
|
||||
@ -37,7 +67,7 @@ class Config:
|
||||
SCODOC_URL = os.environ.get("SCODOC_URL", "http://localhost:5000")
|
||||
SCODOC_LOGIN = os.environ.get("SCODOC_LOGIN", "autosco")
|
||||
SCODOC_PASSWORD = os.environ.get("SCODOC_PASSWORD")
|
||||
SCODOC_CHECK_CERTIFICATE = os.environ.get("SCODOC_CHECK_CERTIFICATE", True)
|
||||
SCODOC_CHECK_CERTIFICATE = to_bool(os.environ.get("SCODOC_CHECK_CERTIFICATE", True))
|
||||
API_TIMEOUT = 120 # 2 minutes
|
||||
API_URL = SCODOC_URL + "/ScoDoc/api"
|
||||
SCODOC_DEPT_ACRONYM = os.environ.get("SCODOC_DEPT_ACRONYM", "ESPL")
|
||||
|
Loading…
x
Reference in New Issue
Block a user