forked from fossasia/open-event-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
143 lines (112 loc) · 3.41 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- coding: utf-8 -*-
import os
from envparse import env
env.read_envfile()
basedir = os.path.abspath(os.path.dirname(__file__))
VERSION_NAME = '2.1.0-alpha.0'
LANGUAGES = {
'en': 'English',
'bn': 'Bengali/Bangla',
'zh_Hans': 'Chinese (Simplified)',
'zh_Hant': 'Chinese (Traditional)',
'fr': 'French',
'de': 'German',
'id': 'Indonesian',
'ko': 'Korean',
'pl': 'Polish',
'es': 'Spanish',
'th': 'Thai',
'vi': 'Vietnamese',
'hi': 'Hindi',
'ja': 'Japanese',
'ru': 'Russian',
}
class Config:
"""
The base configuration option. Contains the defaults.
"""
DEBUG = False
DEVELOPMENT = False
STAGING = False
PRODUCTION = False
TESTING = False
SECRET_KEY = env.str('SECRET_KEY', default=None)
CACHING = False
PROFILE = False
SQLALCHEMY_RECORD_QUERIES = False
FLASK_ADMIN_SWATCH = 'lumen'
VERSION = VERSION_NAME
SQLALCHEMY_TRACK_MODIFICATIONS = True
ERROR_404_HELP = False
CSRF_ENABLED = True
SERVER_NAME = env('SERVER_NAME', default=None)
CORS_HEADERS = 'Content-Type'
SQLALCHEMY_DATABASE_URI = env('DATABASE_URL', default=None)
SQLALCHEMY_ENGINE_OPTIONS = {
'pool_pre_ping': True
}
SERVE_STATIC = env.bool('SERVE_STATIC', default=False)
DATABASE_QUERY_TIMEOUT = 0.1
SENTRY_DSN = env('SENTRY_DSN', default=None)
ENABLE_ELASTICSEARCH = env.bool('ENABLE_ELASTICSEARCH', default=False)
ELASTICSEARCH_HOST = env('ELASTICSEARCH_HOST', default='localhost:9200')
REDIS_URL = env('REDIS_URL', default='redis://localhost:6379/0')
CELERY_BACKKEND = env('CELERY_BACKEND', default='redis')
# API configs
SOFT_DELETE = True
PROPOGATE_ERROR = env.bool('PROPOGATE_ERROR', default=False)
DASHERIZE_API = True
API_PROPOGATE_UNCAUGHT_EXCEPTIONS = env.bool('API_PROPOGATE_UNCAUGHT_EXCEPTIONS', default=True)
ETAG = True
if not SQLALCHEMY_DATABASE_URI:
print('`DATABASE_URL` either not exported or empty')
exit()
BASE_DIR = basedir
FORCE_SSL = os.getenv('FORCE_SSL', 'no') == 'yes'
if SERVE_STATIC:
UPLOADS_FOLDER = BASE_DIR + '/static/uploads/'
TEMP_UPLOADS_FOLDER = BASE_DIR + '/static/uploads/temp/'
UPLOAD_FOLDER = UPLOADS_FOLDER
STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
if FORCE_SSL:
PREFERRED_URL_SCHEME = 'https'
class ProductionConfig(Config):
"""
The configuration for a production environment
"""
ENV = 'production'
MINIFY_PAGE = True
PRODUCTION = True
CACHING = True
class StagingConfig(ProductionConfig):
"""
The configuration for a staging environment
"""
PRODUCTION = False
STAGING = True
class DevelopmentConfig(Config):
"""
The configuration for a development environment
"""
ENV = 'development'
DEVELOPMENT = True
DEBUG = True
CACHING = True
PROPOGATE_ERROR = True
# Test database performance
SQLALCHEMY_RECORD_QUERIES = True
class TestingConfig(Config):
"""
The configuration for a test suit
"""
ENV = 'testing'
TESTING = True
CELERY_TASK_ALWAYS_EAGER = True
CELERY_TASK_EAGER_PROPAGATES = True
SQLALCHEMY_RECORD_QUERIES = True
DEBUG_TB_ENABLED = False
BROKER_BACKEND = 'memory'
SQLALCHEMY_DATABASE_URI = env('TEST_DATABASE_URL', default=None)
PROPOGATE_ERROR = True