-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.py
70 lines (51 loc) · 1.64 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""Configuration for Ochazuke."""
import os
def fix_uri(uri):
if uri.startswith("postgres://"):
uri = uri.replace("postgres://", "postgresql://", 1)
return uri
class Config:
"""Set Flask configuration vars from .env file."""
# General
TESTING = False
FLASK_DEBUG = False
@staticmethod
def init_app(app):
pass
class DevelopmentConfig(Config):
"""Special class for development purpose"""
# export FLASK_ENV=development
# on your local computer
DEBUG = True
# Database
SQLALCHEMY_DATABASE_URI = os.environ.get("DEV_DATABASE_URL")
class TestingConfig(Config):
"""Special class for testing purpose"""
TESTING = True
DEBUG = True
FLASK_DEBUG = True
# Database
SQLALCHEMY_DATABASE_URI = os.environ.get("TEST_DATABASE_URL") or "sqlite://" # noqa
SQLALCHEMY_DATABASE_URI = fix_uri(SQLALCHEMY_DATABASE_URI)
SQLALCHEMY_TRACK_MODIFICATIONS = False
class ProductionConfig(Config):
"""Production Ready Config."""
TESTING = False
DEBUG = False
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
SQLALCHEMY_DATABASE_URI = fix_uri(SQLALCHEMY_DATABASE_URI)
@classmethod
def init_app(cls, app):
Config.init_app(app)
config = {
"development": DevelopmentConfig,
"testing": TestingConfig,
"production": ProductionConfig,
# Secure Fallback
"default": DevelopmentConfig,
}