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

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

## 53 statements

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

1 import json

2 import os

3

4 from flask import Blueprint

5 from flask import current_app

6 from flask import redirect

7 from flask import render_template

8 from flask import url_for

9 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

12

13 from shopyo.api.file import get_folders

14

15# from flask import flash

16# from flask import request

17# from shopyo.api.html import notify_success

18# from init import db

19

20# from modules.box__default.settings.models import Settings

21

22# from shopyo.api.forms import flash_errors

23

24

25 dirpath = os.path.dirname(os.path.abspath(__file__))

26 module_info = {}

27

28 with open(dirpath + "/info.json") as f:

29 module_info = json.load(f)

30

31 globals()["{}_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)

37

38 module_settings = {"module_info": module_info}

39

40 module_blueprint = globals()["{}_blueprint".format(module_info["module_name"])]

41

42

43@module_blueprint.route("/")

44@login_required

45 def index():

46

47 context = {}

48

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)

59

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)

70

71 active_front_theme = get_setting("ACTIVE_FRONT_THEME")

72 active_back_theme = get_setting("ACTIVE_BACK_THEME")

73

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)

83

84 return render_template(

85 "{}/index.html".format(module_info["module_name"]), **context

86 )

87

88

89@module_blueprint.route("/activate/front/<theme_name>")

90@login_required

91 def activate_front_theme(theme_name):

92 set_setting("ACTIVE_FRONT_THEME", theme_name)

93

94 # with app.app_context():

95

96 # current_app.jinja_loader,

97 # print(current_app.jinja_loader.list_templates())

98 return redirect(url_for("{}.index".format(module_info["module_name"])))

99

100

101@module_blueprint.route("/activate/back/<theme_name>")

102@login_required

103 def activate_back_theme(theme_name):

104 set_setting("ACTIVE_BACK_THEME", theme_name)

105

106 # with app.app_context():

107

108 # current_app.jinja_loader,

109 # print(current_app.jinja_loader.list_templates())

110 return redirect(url_for("{}.index".format(module_info["module_name"])))