Skip to content

Commit 3477e5d

Browse files
author
Moyo Oyegunle
committed
Updating
1 parent db39b99 commit 3477e5d

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ accounts.db
33
# Byte-compiled / optimized / DLL files
44
__pycache__/
55
*.py[cod]
6+
*.pyc
67
*$py.class
78

89
# C extensions
@@ -162,3 +163,6 @@ htmlcov/
162163
.coverage
163164
.coverage.*
164165
*,cover
166+
167+
#VSCode
168+
.vscode/

app/main/routes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
from app.main.forms import PostForm
88
from app.models import KeyStore
99
from config import Config
10-
11-
12-
10+
from config import myclassvariables
1311

1412
def refresh_db(url):
1513
form = PostForm()
@@ -37,7 +35,7 @@ def index():
3735
db_value = {}
3836
db_time = {}
3937
db_remove = {}
40-
configs = Config.myclassvariables()
38+
configs = myclassvariables()
4139

4240

4341
if not Config.DB_INIT:

app/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{% block content %}
44

5-
<h1>Jennison Openshift Demo</h1>
5+
<h1>Openshift Demo</h1>
66

77
<h2> Active Configuration </h2>
88
{% for configuration,value in configs.items() %}

config.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,32 @@
55
load_dotenv(os.path.join(basedir, '.env'))
66

77

8+
def create_uri(user,password,host,db):
9+
if ( user != "" and password != "" and host != "" and db != ""):
10+
return "mysql+pymysql://{}:{}@{}/{}".format(user,password, host,db)
11+
else:
12+
return "sqlite:///:memory:"
13+
14+
815
class Config(object):
916
#Secret key Configuration for Flask not for application
1017
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'
11-
12-
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI') or "sqlite:///:memory:"
1318
SQLALCHEMY_DATABASE_USERNAME = os.environ.get('DATABASE_USERNAME') or ""
1419
SQLALCHEMY_DATABASE_PASSWORD = os.environ.get('DATABASE_PASSWORD') or ""
20+
SQLALCHEMY_DATABASE_HOST = os.environ.get('DATABASE_HOST') or ""
21+
SQLALCHEMY_DATABASE_DB = os.environ.get('DATABASE_DB') or ""
1522
SQLALCHEMY_TRACK_MODIFICATIONS = False
1623
DB_INIT = False
1724

18-
def myclassvariables():
19-
temp = {}
20-
result = vars(Config)
21-
for key in result:
22-
if "__" not in key and "<" not in key and "myclassvariables" not in key :
23-
temp.update({key:result[key]})
24-
return temp
25+
#Generate URI from Parameters
26+
SQLALCHEMY_DATABASE_URI = create_uri(SQLALCHEMY_DATABASE_USERNAME,SQLALCHEMY_DATABASE_PASSWORD,SQLALCHEMY_DATABASE_HOST,
27+
SQLALCHEMY_DATABASE_DB)
28+
29+
def myclassvariables():
30+
temp = {}
31+
result = vars(Config)
32+
for key in result:
33+
if "__" not in key and "<" not in key and "myclassvariables" not in key :
34+
temp.update({key:result[key]})
35+
return temp
36+

0 commit comments

Comments
 (0)