33Copyright (c) 2019 - present AppSeed.us
44"""
55
6- import os
6+ import os , random , string
77
88class Config (object ):
99
1010 basedir = os .path .abspath (os .path .dirname (__file__ ))
1111
12+ # Assets Management
13+ ASSETS_ROOT = os .getenv ('ASSETS_ROOT' , '/static/assets' )
14+
1215 # Set up the App SECRET_KEY
13- # SECRET_KEY = config('SECRET_KEY' , default='S#perS3crEt_007')
14- SECRET_KEY = os .getenv ('SECRET_KEY' , 'S#perS3crEt_007' )
16+ SECRET_KEY = os .getenv ('SECRET_KEY' , None )
17+ if not SECRET_KEY :
18+ SECRET_KEY = '' .join (random .choice ( string .ascii_lowercase ) for i in range ( 32 ))
1519
16- # This will create a file in <app> FOLDER
17- SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os .path .join (basedir , 'db.sqlite3' )
18- SQLALCHEMY_TRACK_MODIFICATIONS = False
20+ SQLALCHEMY_TRACK_MODIFICATIONS = False
1921
20- # Assets Management
21- ASSETS_ROOT = os .getenv ('ASSETS_ROOT' , '/static/assets' )
22+ DB_ENGINE = os .getenv ('DB_ENGINE' , None )
23+ DB_USERNAME = os .getenv ('DB_USERNAME' , None )
24+ DB_PASS = os .getenv ('DB_PASS' , None )
25+ DB_HOST = os .getenv ('DB_HOST' , None )
26+ DB_PORT = os .getenv ('DB_PORT' , None )
27+ DB_NAME = os .getenv ('DB_NAME' , None )
28+
29+ USE_SQLITE = True
30+
31+ # try to set up a Relational DBMS
32+ if DB_ENGINE and DB_NAME and DB_USERNAME :
33+
34+ try :
35+
36+ # Relational DBMS: PSQL, MySql
37+ SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}' .format (
38+ DB_ENGINE ,
39+ DB_USERNAME ,
40+ DB_PASS ,
41+ DB_HOST ,
42+ DB_PORT ,
43+ DB_NAME
44+ )
45+
46+ USE_SQLITE = False
47+
48+ except Exception as e :
49+
50+ print ('> Error: DBMS Exception: ' + str (e ) )
51+ print ('> Fallback to SQLite ' )
52+
53+ if USE_SQLITE :
54+
55+ # This will create a file in <app> FOLDER
56+ SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os .path .join (basedir , 'db.sqlite3' )
2257
2358class ProductionConfig (Config ):
2459 DEBUG = False
@@ -28,15 +63,6 @@ class ProductionConfig(Config):
2863 REMEMBER_COOKIE_HTTPONLY = True
2964 REMEMBER_COOKIE_DURATION = 3600
3065
31- # PostgreSQL database
32- SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}' .format (
33- os .getenv ('DB_ENGINE' , 'mysql' ),
34- os .getenv ('DB_USERNAME' , 'appseed_db_usr' ),
35- os .getenv ('DB_PASS' , 'pass' ),
36- os .getenv ('DB_HOST' , 'localhost' ),
37- os .getenv ('DB_PORT' , 3306 ),
38- os .getenv ('DB_NAME' , 'appseed_db' )
39- )
4066
4167class DebugConfig (Config ):
4268 DEBUG = True
0 commit comments