Last active
May 31, 2020 04:26
-
-
Save ardydedase/cd4269208b734f868aa45a609608aa76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from utils import get_env_variable | |
| POSTGRES_URL = get_env_variable('POSTGRES_URL') | |
| POSTGRES_USER = get_env_variable('POSTGRES_USER') | |
| POSTGRES_PASSWORD = get_env_variable('POSTGRES_PASSWORD') | |
| POSTGRES_DB = get_env_variable('POSTGRES_DB') | |
| class Config(object): | |
| DEBUG = False | |
| TESTING = False | |
| # SQLAlchemy | |
| uri_template = 'postgresql+psycopg2://{user}:{pw}@{url}/{db}' | |
| SQLALCHEMY_DATABASE_URI = uri_template.format( | |
| user=POSTGRES_USER, | |
| pw=POSTGRES_PASSWORD, | |
| url=POSTGRES_URL, | |
| db=POSTGRES_DB) | |
| # Silence the deprecation warning | |
| SQLALCHEMY_TRACK_MODIFICATIONS = False | |
| # API settings | |
| API_PAGINATION_PER_PAGE = 10 | |
| class DevelopmentConfig(Config): | |
| DEBUG = True | |
| class TestConfig(Config): | |
| TESTING = True | |
| class ProductionConfig(Config): | |
| # production config | |
| pass | |
| def get_config(env=None): | |
| if env is None: | |
| try: | |
| env = get_env_variable('ENV') | |
| except Exception: | |
| env = 'development' | |
| print('env is not set, using env:', env) | |
| if env == 'production': | |
| return ProductionConfig() | |
| elif env == 'test': | |
| return TestConfig() | |
| return DevelopmentConfig() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment