2021-05-29 18:22:51 +02:00
|
|
|
# -*- coding: UTF-8 -*
|
|
|
|
|
|
|
|
import os
|
2023-02-27 09:46:15 +01:00
|
|
|
import logging
|
2021-05-29 18:22:51 +02:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
BASEDIR = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
load_dotenv(os.path.join(BASEDIR, ".env"))
|
|
|
|
|
|
|
|
|
2021-07-20 17:32:04 +02:00
|
|
|
class Config:
|
2021-05-31 00:14:15 +02:00
|
|
|
"""General configuration. Mostly loaded from environment via .env"""
|
2021-05-29 18:22:51 +02:00
|
|
|
|
2021-08-27 10:49:36 +02:00
|
|
|
SQLALCHEMY_DATABASE_URI = None # set in subclass
|
|
|
|
FLASK_ENV = None # # set in subclass
|
2022-05-04 23:11:20 +02:00
|
|
|
SECRET_KEY = os.environ.get("SECRET_KEY") or "90e01e75831e4276a4c70d29564b425f"
|
2021-05-29 18:22:51 +02:00
|
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
|
|
LOG_TO_STDOUT = os.environ.get("LOG_TO_STDOUT")
|
2023-02-27 09:46:15 +01:00
|
|
|
LOG_LEVEL = getattr(logging, os.environ.get("LOG_LEVEL", "INFO"), "INFO")
|
2021-08-27 10:49:36 +02:00
|
|
|
MAIL_SERVER = os.environ.get("MAIL_SERVER", "localhost")
|
|
|
|
MAIL_PORT = int(os.environ.get("MAIL_PORT", 25))
|
2021-05-29 18:22:51 +02:00
|
|
|
MAIL_USE_TLS = os.environ.get("MAIL_USE_TLS") is not None
|
|
|
|
MAIL_USERNAME = os.environ.get("MAIL_USERNAME")
|
|
|
|
MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD")
|
|
|
|
LANGUAGES = ["fr", "en"] # unused for now
|
|
|
|
SCODOC_ADMIN_MAIL = os.environ.get("SCODOC_ADMIN_MAIL")
|
|
|
|
SCODOC_ADMIN_LOGIN = os.environ.get("SCODOC_ADMIN_LOGIN") or "admin"
|
|
|
|
ADMINS = [SCODOC_ADMIN_MAIL]
|
|
|
|
SCODOC_ERR_MAIL = os.environ.get("SCODOC_ERR_MAIL")
|
2022-01-19 22:40:41 +01:00
|
|
|
# Le "from" des mails émis. Attention: peut être remplacée par la préférence email_from_addr:
|
|
|
|
SCODOC_MAIL_FROM = os.environ.get("SCODOC_MAIL_FROM") or ("no-reply@" + MAIL_SERVER)
|
|
|
|
|
2021-05-29 18:22:51 +02:00
|
|
|
BOOTSTRAP_SERVE_LOCAL = os.environ.get("BOOTSTRAP_SERVE_LOCAL")
|
2021-07-25 09:51:09 +02:00
|
|
|
SCODOC_DIR = os.environ.get("SCODOC_DIR", "/opt/scodoc")
|
|
|
|
SCODOC_VAR_DIR = os.environ.get("SCODOC_VAR_DIR", "/opt/scodoc-data")
|
2021-08-29 19:57:32 +02:00
|
|
|
SCODOC_LOG_FILE = os.path.join(SCODOC_VAR_DIR, "log", "scodoc.log")
|
2021-09-15 00:33:30 +02:00
|
|
|
# evite confusion avec le log nginx scodoc_error.log:
|
|
|
|
SCODOC_ERR_FILE = os.path.join(SCODOC_VAR_DIR, "log", "scodoc_exc.log")
|
2021-09-08 23:00:01 +02:00
|
|
|
#
|
2021-10-19 15:57:28 +02:00
|
|
|
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # Flask uploads (16Mo, en ligne avec nginx)
|
2023-04-06 16:10:32 +02:00
|
|
|
# flask_json:
|
|
|
|
JSON_ADD_STATUS = False
|
|
|
|
JSON_USE_ENCODE_METHODS = True
|
2023-07-11 10:24:00 +02:00
|
|
|
JSON_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z" # "%Y-%m-%dT%H:%M:%S"
|
2021-08-09 23:23:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ProdConfig(Config):
|
2022-05-04 23:11:20 +02:00
|
|
|
"mode production, normalement derrière nginx/gunicorn"
|
2021-08-09 23:23:11 +02:00
|
|
|
FLASK_ENV = "production"
|
|
|
|
DEBUG = False
|
|
|
|
TESTING = False
|
|
|
|
SQLALCHEMY_DATABASE_URI = (
|
|
|
|
os.environ.get("SCODOC_DATABASE_URI") or "postgresql:///SCODOC"
|
|
|
|
)
|
2021-08-27 18:17:45 +02:00
|
|
|
PREFERRED_URL_SCHEME = "https"
|
2021-08-09 23:23:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
class DevConfig(Config):
|
2022-05-04 23:11:20 +02:00
|
|
|
"mode développement"
|
2021-08-09 23:23:11 +02:00
|
|
|
FLASK_ENV = "development"
|
|
|
|
DEBUG = True
|
2021-08-21 19:51:33 +02:00
|
|
|
TESTING = False
|
2021-08-09 23:23:11 +02:00
|
|
|
SQLALCHEMY_DATABASE_URI = (
|
2024-02-27 21:23:45 +01:00
|
|
|
os.environ.get("SCODOC_DATABASE_URI") or "postgresql:///SCODOC_DEV"
|
2021-08-09 23:23:11 +02:00
|
|
|
)
|
2021-08-21 13:40:47 +02:00
|
|
|
SECRET_KEY = os.environ.get("DEV_SECRET_KEY") or "bb3faec7d9a34eb68a8e3e710087d87a"
|
2022-07-21 16:46:07 +02:00
|
|
|
# pour le avoir url_for dans le shell:
|
2024-02-27 21:23:45 +01:00
|
|
|
# SERVER_NAME = os.environ.get("SCODOC_TEST_SERVER_NAME") or "localhost"
|
2021-08-09 23:23:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestConfig(DevConfig):
|
2022-05-04 23:11:20 +02:00
|
|
|
"Pour les tests unitaires"
|
2021-08-21 19:51:33 +02:00
|
|
|
TESTING = True
|
2023-01-11 20:39:58 +01:00
|
|
|
DEBUG = False
|
2021-08-09 23:23:11 +02:00
|
|
|
SQLALCHEMY_DATABASE_URI = (
|
2021-09-21 15:55:09 +02:00
|
|
|
os.environ.get("SCODOC_TEST_DATABASE_URI") or "postgresql:///SCODOC_TEST"
|
2021-08-09 23:23:11 +02:00
|
|
|
)
|
2021-08-21 13:40:47 +02:00
|
|
|
SERVER_NAME = os.environ.get("SCODOC_TEST_SERVER_NAME") or "test.gr"
|
2021-08-10 12:57:38 +02:00
|
|
|
DEPT_TEST = "TEST_" # nom du département, ne pas l'utiliser pour un "vrai"
|
2021-08-21 13:40:47 +02:00
|
|
|
SECRET_KEY = os.environ.get("TEST_SECRET_KEY") or "c7ecff5db1594c208f573ff30e0f6bca"
|
2021-08-19 23:12:42 +02:00
|
|
|
|
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
class TestAPIConfig(Config):
|
|
|
|
"Pour les tests de l'API"
|
|
|
|
FLASK_ENV = "test_api"
|
|
|
|
TESTING = False
|
|
|
|
DEBUG = True
|
|
|
|
SQLALCHEMY_DATABASE_URI = (
|
|
|
|
os.environ.get("SCODOC_TEST_API_DATABASE_URI")
|
|
|
|
or "postgresql:///SCODOC_TEST_API"
|
|
|
|
)
|
|
|
|
DEPT_TEST = "TAPI_" # nom du département, ne pas l'utiliser pour un "vrai"
|
|
|
|
SECRET_KEY = os.environ.get("TEST_SECRET_KEY") or "c7ecff5db15946789Hhahbh88aja175"
|
|
|
|
|
|
|
|
|
2021-08-19 23:12:42 +02:00
|
|
|
mode = os.environ.get("FLASK_ENV", "production")
|
|
|
|
if mode == "production":
|
|
|
|
RunningConfig = ProdConfig
|
|
|
|
elif mode == "development":
|
|
|
|
RunningConfig = DevConfig
|
|
|
|
elif mode == "test":
|
|
|
|
RunningConfig = TestConfig
|
2022-05-04 23:11:20 +02:00
|
|
|
elif mode == "test_api":
|
|
|
|
RunningConfig = TestAPIConfig
|