Skip to content

Commit 9b3f458

Browse files
chore: use env vars for site settings
1 parent 1b06586 commit 9b3f458

6 files changed

Lines changed: 17 additions & 19 deletions

File tree

pythoncms/app.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,16 @@ def setup_theme_paths(app):
258258
def inject_global_vars(app, global_template_variables):
259259
@app.context_processor
260260
def inject_global_vars():
261-
APP_NAME = "dwdwefw"
262-
261+
APP_NAME = os.environ.get('APP_NAME', 'Demo')
262+
def get_setting(env_var):
263+
return os.environ.get(env_var)
264+
263265
base_context = {
264266
"APP_NAME": APP_NAME,
265267
"len": len,
266268
"current_user": current_user,
267269
"get_static": get_static,
270+
"get_setting": get_setting
268271
}
269272
base_context.update(global_template_variables)
270273

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .helpers import *
1+
# from .helpers import *
22

3-
available_everywhere = {"get_setting": get_setting}
3+
# available_everywhere = {"get_setting": get_setting}

pythoncms/modules/box__default/theme/helpers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
from flask import url_for
55
from init import themes_path
6-
from modules.box__default.settings.helpers import get_setting
76

87

98
def get_front_theme_dir():
10-
theme_dir = os.path.join(themes_path, "front", get_setting("ACTIVE_FRONT_THEME"))
9+
theme_dir = os.path.join(themes_path, "front", os.environ.get('ACTIVE_FRONT_THEME', 'editorial'))
1110
return theme_dir
1211

1312

@@ -19,7 +18,7 @@ def get_front_theme_info_data():
1918

2019

2120
def get_active_front_theme():
22-
return get_setting("ACTIVE_FRONT_THEME")
21+
return os.environ.get('ACTIVE_FRONT_THEME', 'editorial')
2322

2423

2524
def get_active_front_theme_version():
@@ -35,7 +34,7 @@ def get_active_front_theme_styles_url():
3534

3635

3736
def get_back_theme_dir():
38-
theme_dir = os.path.join(themes_path, "back", get_setting("ACTIVE_BACK_THEME"))
37+
theme_dir = os.path.join(themes_path, "back", os.environ.get('ACTIVE_BACK_THEME', 'sneat'))
3938
return theme_dir
4039

4140

@@ -47,7 +46,7 @@ def get_back_theme_info_data():
4746

4847

4948
def get_active_back_theme():
50-
return get_setting("ACTIVE_BACK_THEME")
49+
return os.environ.get('ACTIVE_BACK_THEME', 'sneat')
5150

5251

5352
def get_active_back_theme_version():

pythoncms/modules/box__default/theme/view.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from flask import render_template
88
from flask import url_for
99
from flask_login import login_required
10-
from modules.box__default.settings.helpers import get_setting
11-
from modules.box__default.settings.helpers import set_setting
1210
from shopyo.api.file import get_folders
1311

1412
# from flask import flash
@@ -67,8 +65,8 @@ def index():
6765
with open(info_path) as f:
6866
all_back_info[folder] = json.load(f)
6967

70-
active_front_theme = get_setting("ACTIVE_FRONT_THEME")
71-
active_back_theme = get_setting("ACTIVE_BACK_THEME")
68+
active_front_theme = os.environ.get('ACTIVE_FRONT_THEME', 'editorial')
69+
active_back_theme = os.environ.get('ACTIVE_BACK_THEME', 'SNEAT')
7270

7371
context.update(
7472
{
@@ -88,7 +86,7 @@ def index():
8886
@module_blueprint.route("/activate/front/<theme_name>")
8987
@login_required
9088
def activate_front_theme(theme_name):
91-
set_setting("ACTIVE_FRONT_THEME", theme_name)
89+
os.environ['ACTIVE_FRONT_THEME"'] = theme_name
9290

9391
# with app.app_context():
9492

@@ -100,7 +98,7 @@ def activate_front_theme(theme_name):
10098
@module_blueprint.route("/activate/back/<theme_name>")
10199
@login_required
102100
def activate_back_theme(theme_name):
103-
set_setting("ACTIVE_BACK_THEME", theme_name)
101+
os.environ['ACTIVE_BACK_THEME"'] = theme_name
104102

105103
# with app.app_context():
106104

pythoncms/modules/resource/view.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# from flask_login import login_required
1414
# from PIL import Image as PILimage
1515

16-
# from shopyo.api.enhance import get_setting
1716
# from shopyo.api.file import delete_file
1817

1918
# from modules.box__ecommerce.product.models import Product

pythoncms/modules/www/view.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# from shopyo.api.html import notify_success
1212
# from shopyo.api.forms import flash_errors
1313
# from shopyo.api.enhance import get_active_theme_dir
14-
# from shopyo.api.enhance import get_setting
1514
# from modules.box__ecommerce.shop.helpers import get_cart_data
1615

1716
mhelp = ModuleHelp(__file__, __name__)
@@ -23,13 +22,13 @@
2322
def index():
2423
# cant be defined above but must be manually set each time
2524
# active_theme_dir = os.path.join(
26-
# dirpath, "..", "..", "themes", get_setting("ACTIVE_FRONT_THEME")
25+
# dirpath, "..", "..", "themes", os.environ.get('ACTIVE_FRONT_THEME")
2726
# )
2827
# module_blueprint.template_folder = active_theme_dir
2928

3029
# return str(module_blueprint.template_folder)
3130

32-
# return render_template(get_setting("ACTIVE_FRONT_THEME") + "/index.html")
31+
# return render_template(os.environ.get('ACTIVE_FRONT_THEME") + "/index.html")
3332

3433
return render_template(
3534
f"{get_active_front_theme()}/index.html", get_static=get_static

0 commit comments

Comments
 (0)