Coverage for modules/box__default/dashboard/view.py : 32%

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 flash
7from flask import render_template
8from flask_login import login_required
9from modules.box__default.auth.decorators import check_confirmed
11from shopyo.api.html import notify_success
12from shopyo.api.module import ModuleHelp
14mhelp = ModuleHelp(__file__, __name__)
15globals()[mhelp.blueprint_str] = mhelp.blueprint
16module_blueprint = globals()[mhelp.blueprint_str]
19all_info = {}
22@dashboard_blueprint.route("/")
23@login_required
24@check_confirmed
25def index():
26 context = {}
28 for folder in os.listdir(os.path.join(current_app.config["BASE_DIR"], "modules")):
29 if folder.startswith("__"):
30 continue
31 elif folder.startswith("box__"):
32 for sub_folder in os.listdir(
33 os.path.join(current_app.config["BASE_DIR"], "modules", folder)
34 ):
35 if sub_folder in ["dashboard"]:
36 continue
37 if sub_folder.startswith("__"): # ignore __pycache__
38 continue
39 elif sub_folder.endswith(".json"): # box_info.json
40 continue
41 with open(
42 os.path.join(
43 current_app.config["BASE_DIR"],
44 "modules",
45 folder,
46 sub_folder,
47 "info.json",
48 )
49 ) as f:
50 module_info = json.load(f)
51 all_info[sub_folder] = module_info
52 else:
54 if folder not in ["dashboard"]:
55 with open(
56 os.path.join(
57 current_app.config["BASE_DIR"],
58 "modules",
59 folder,
60 "info.json",
61 )
62 ) as f:
63 module_info = json.load(f)
64 all_info[folder] = module_info
66 context["all_info"] = all_info
67 flash(notify_success("Notif test"))
68 return render_template("dashboard/index.html", **context)