Coverage for modules/box__default/theme/view.py : 47%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import json
2import os
4from flask import Blueprint
5from flask import current_app
6from flask import redirect
7from flask import render_template
8from flask import url_for
9from flask_login import login_required
10from modules.box__default.settings.helpers import get_setting
11from modules.box__default.settings.helpers import set_setting
13from shopyo.api.file import get_folders
15# from flask import flash
16# from flask import request
17# from shopyo.api.html import notify_success
18# from init import db
20# from modules.box__default.settings.models import Settings
22# from shopyo.api.forms import flash_errors
25dirpath = os.path.dirname(os.path.abspath(__file__))
26module_info = {}
28with open(dirpath + "/info.json") as f:
29 module_info = json.load(f)
31globals()["{}_blueprint".format(module_info["module_name"])] = Blueprint(
32 "{}".format(module_info["module_name"]),
33 __name__,
34 template_folder="templates",
35 url_prefix=module_info["url_prefix"],
36)
38module_settings = {"module_info": module_info}
40module_blueprint = globals()["{}_blueprint".format(module_info["module_name"])]
43@module_blueprint.route("/")
44@login_required
45def index():
47 context = {}
49 front_themes_path = os.path.join(
50 current_app.config["BASE_DIR"], "static", "themes", "front"
51 )
52 all_front_info = {}
53 front_theme_folders = get_folders(front_themes_path)
54 for folder in front_theme_folders:
55 theme_path = os.path.join(front_themes_path, folder)
56 info_path = os.path.join(theme_path, "info.json")
57 with open(info_path) as f:
58 all_front_info[folder] = json.load(f)
60 back_themes_path = os.path.join(
61 current_app.config["BASE_DIR"], "static", "themes", "back"
62 )
63 all_back_info = {}
64 back_theme_folders = get_folders(back_themes_path)
65 for folder in back_theme_folders:
66 theme_path = os.path.join(back_themes_path, folder)
67 info_path = os.path.join(theme_path, "info.json")
68 with open(info_path) as f:
69 all_back_info[folder] = json.load(f)
71 active_front_theme = get_setting("ACTIVE_FRONT_THEME")
72 active_back_theme = get_setting("ACTIVE_BACK_THEME")
74 context.update(
75 {
76 "all_front_info": all_front_info,
77 "all_back_info": all_back_info,
78 "active_front_theme": active_front_theme,
79 "active_back_theme": active_back_theme,
80 }
81 )
82 context.update(module_settings)
84 return render_template(
85 "{}/index.html".format(module_info["module_name"]), **context
86 )
89@module_blueprint.route("/activate/front/<theme_name>")
90@login_required
91def activate_front_theme(theme_name):
92 set_setting("ACTIVE_FRONT_THEME", theme_name)
94 # with app.app_context():
96 # current_app.jinja_loader,
97 # print(current_app.jinja_loader.list_templates())
98 return redirect(url_for("{}.index".format(module_info["module_name"])))
101@module_blueprint.route("/activate/back/<theme_name>")
102@login_required
103def activate_back_theme(theme_name):
104 set_setting("ACTIVE_BACK_THEME", theme_name)
106 # with app.app_context():
108 # current_app.jinja_loader,
109 # print(current_app.jinja_loader.list_templates())
110 return redirect(url_for("{}.index".format(module_info["module_name"])))