shopyo-theme 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.1
2
+ Name: shopyo_theme
3
+ Version: 1.0.1
4
+ Summary: Module for managing settings in shopyo
5
+ Author-email: Abdur-Rahmaan Janhangeer <arj.python@gmail.com>
6
+ Project-URL: Homepage, https://github.com/shopyo/shopyo
7
+ Project-URL: Bug Tracker, https://github.com/shopyo/shopyo/issues
8
+ Keywords: shopyo
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Requires-Dist: shopyo
14
+ Requires-Dist: shopyo_settings
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "shopyo_theme"
3
+ authors = [{ name = "Abdur-Rahmaan Janhangeer", email = "arj.python@gmail.com" }]
4
+ description = "Module for managing settings in shopyo"
5
+ # readme = "README.md"
6
+ requires-python = ">=3.8"
7
+ # license = { file = "LICENSE.txt" }
8
+ keywords = ["shopyo"]
9
+ classifiers = [
10
+ "Programming Language :: Python :: 3",
11
+ "License :: OSI Approved :: BSD License",
12
+ "Operating System :: OS Independent",
13
+ ]
14
+ dependencies = ["shopyo", "shopyo_settings"]
15
+ dynamic = ["version"]
16
+
17
+ [tool.setuptools.dynamic]
18
+ version = { attr = "shopyo_theme.__version__" }
19
+
20
+ [project.urls]
21
+ "Homepage" = "https://github.com/shopyo/shopyo"
22
+ "Bug Tracker" = "https://github.com/shopyo/shopyo/issues"
23
+
24
+ [build-system]
25
+ requires = ["setuptools>=61.0"]
26
+ build-backend = "setuptools.build_meta"
27
+
28
+ [tool.setuptools]
29
+ include-package-data = true
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["."]
33
+ exclude = ["tests*", "docs*", "examples*"]
34
+
35
+ [tool.setuptools.package-data]
36
+ shopyo_theme = ["static/**", "templates/**", "*.json"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,43 @@
1
+ from typing import Any
2
+ import os
3
+ import json
4
+ from flask import Flask
5
+ from shopyo_theme.view import module_blueprint
6
+ from .helpers import *
7
+
8
+
9
+ __version__ = "1.0.1"
10
+
11
+ info = {}
12
+ with open(os.path.dirname(os.path.abspath(__file__)) + os.sep + "info.json") as f:
13
+ info = json.load(f)
14
+
15
+
16
+ class ShopyoTheme:
17
+ def __init__(self, app: Any = None) -> None:
18
+ if app is not None:
19
+ self.init_app(app)
20
+
21
+ self.get_front_theme_dir = get_front_theme_dir
22
+ self.get_front_theme_info_data = get_front_theme_info_data
23
+ self.get_active_front_theme = get_active_front_theme
24
+ self.get_active_front_theme_version = get_active_front_theme_version
25
+ self.get_active_front_theme_styles_url = get_active_front_theme_styles_url
26
+ self.get_back_theme_dir = get_back_theme_dir
27
+ self.get_back_theme_info_data = get_back_theme_info_data
28
+ self.get_active_back_theme = get_active_back_theme
29
+ self.get_active_back_theme_version = get_active_back_theme_version
30
+ self.get_active_back_theme_styles_url = get_active_back_theme_styles_url
31
+
32
+
33
+ def init_app(self, app: Flask) -> None:
34
+ if not hasattr(app, "extensions"):
35
+ app.extensions = {}
36
+
37
+ app.extensions["shopyo_theme"] = self
38
+ bp = module_blueprint
39
+ app.register_blueprint(bp)
40
+ app.jinja_env.globals["shopyo_theme"] = self
41
+
42
+ def get_info(self):
43
+ return info
File without changes
@@ -0,0 +1,64 @@
1
+ import json
2
+ import os
3
+
4
+ from flask import url_for
5
+ from init import themes_path
6
+ from shopyo_settings.helpers import get_setting
7
+
8
+
9
+ def get_front_theme_dir():
10
+ theme_dir = os.path.join(themes_path, "front", get_setting("ACTIVE_FRONT_THEME"))
11
+ return theme_dir
12
+
13
+
14
+ def get_front_theme_info_data():
15
+ info_path = os.path.join(get_front_theme_dir(), "info.json")
16
+ with open(info_path) as f:
17
+ info_data = json.load(f)
18
+ return info_data
19
+
20
+
21
+ def get_active_front_theme():
22
+ return get_setting("ACTIVE_FRONT_THEME")
23
+
24
+
25
+ def get_active_front_theme_version():
26
+ return get_front_theme_info_data()["version"]
27
+
28
+
29
+ def get_active_front_theme_styles_url():
30
+ return url_for(
31
+ "resource.active_front_theme_css",
32
+ active_theme=get_active_front_theme(),
33
+ v=get_active_front_theme_version(),
34
+ )
35
+
36
+
37
+ def get_back_theme_dir():
38
+ theme_dir = os.path.join(themes_path, "back", get_setting("ACTIVE_BACK_THEME"))
39
+ return theme_dir
40
+
41
+
42
+ def get_back_theme_info_data():
43
+ info_path = os.path.join(get_back_theme_dir(), "info.json")
44
+ with open(info_path) as f:
45
+ info_data = json.load(f)
46
+ return info_data
47
+
48
+
49
+ def get_active_back_theme():
50
+ return get_setting("ACTIVE_BACK_THEME")
51
+
52
+
53
+ def get_active_back_theme_version():
54
+ return get_back_theme_info_data()["version"]
55
+
56
+
57
+ def get_active_back_theme_styles_url():
58
+ return url_for(
59
+ "resource.active_back_theme_css",
60
+ active_theme=get_active_back_theme(),
61
+ v=get_active_back_theme_version(),
62
+ )
63
+
64
+
@@ -0,0 +1,12 @@
1
+ {
2
+ "display_string": "Theme",
3
+ "module_name":"shopyo_theme",
4
+ "type": "show",
5
+ "fa-icon": "fa fa-palette",
6
+ "url_prefix": "/shopyo_theme",
7
+ "author": {
8
+ "name":"",
9
+ "website":"https://www.pythonkitchen.com/about-me/",
10
+ "mail":"arj.python@gmail.com"
11
+ }
12
+ }
File without changes
@@ -0,0 +1,7 @@
1
+ {{
2
+ sidebar_item(
3
+ 'Home',
4
+ icon=module_info['fa-icon'],
5
+ url=url_for('{}.index'.format(module_info['module_name']))
6
+ )
7
+ }}
@@ -0,0 +1,91 @@
1
+ {% extends "shopyo_base/module_base.html" %}
2
+
3
+ {% set active_page ='' %}
4
+
5
+ {% block pagehead %}
6
+ <title></title>
7
+ <style>
8
+
9
+ </style>
10
+ {% endblock %}
11
+
12
+
13
+
14
+
15
+ {% block sidebar %}
16
+ {%include '{}/blocks/sidebar.html'.format(module_info['module_name'])%}
17
+ {%endblock%}
18
+
19
+
20
+
21
+
22
+ {% block content %}
23
+ <br>
24
+ <div class="card" style="color: black">
25
+ <div class="card-header">
26
+ Front Theme
27
+ </div>
28
+ <div class="card-body">
29
+ <table class="table">
30
+ <thead>
31
+ <tr>
32
+ <th>Name</th>
33
+ <th>Author</th>
34
+ <th></th>
35
+ </tr>
36
+ </thead>
37
+ <tbody>
38
+ {%for key in all_front_info%}
39
+ <tr>
40
+ <td>{{key}}</td>
41
+ <td>{{all_front_info[key]['author']}}</td>
42
+ <td>
43
+ {%if active_front_theme != key%}
44
+ <a class="btn btn-info" href="{{url_for('shopyo_theme.activate_front_theme', theme_name=key)}}">activate</a>
45
+ {%else%}
46
+ active
47
+ {%endif%}
48
+ </td>
49
+ </tr>
50
+ {%endfor%}
51
+ </tbody>
52
+ </table>
53
+ </div>
54
+ </div>
55
+ <br>
56
+ <div class="card" style="color: black">
57
+ <div class="card-header">
58
+ Back Theme
59
+ </div>
60
+ <div class="card-body">
61
+ <table class="table">
62
+ <thead>
63
+ <tr>
64
+ <th>Name</th>
65
+ <th>Author</th>
66
+ <th></th>
67
+ </tr>
68
+ </thead>
69
+ <tbody>
70
+ {%for key in all_back_info%}
71
+ <tr>
72
+ <td>{{key}}</td>
73
+ <td>{{all_back_info[key]['author']}}</td>
74
+ <td>
75
+ {%if active_back_theme != key%}
76
+ <a class="btn btn-info" href="{{url_for('shopyo_theme.activate_back_theme', theme_name=key)}}">activate</a>
77
+ {%else%}
78
+ active
79
+ {%endif%}
80
+ </td>
81
+ </tr>
82
+ {%endfor%}
83
+ </tbody>
84
+ </table>
85
+ </div>
86
+ </div>
87
+ <div>
88
+
89
+ </div>
90
+
91
+ {% endblock %}
@@ -0,0 +1,113 @@
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 shopyo_appadmin.admin import admin_required
11
+ from shopyo_settings.helpers import get_setting
12
+ from shopyo_settings.helpers import set_setting
13
+
14
+ from shopyo.api.file import get_folders
15
+
16
+ # from flask import flash
17
+ # from flask import request
18
+ # from shopyo.api.html import notify_success
19
+ # from init import db
20
+
21
+ # from modules.box__default.settings.models import Settings
22
+
23
+ # from shopyo.api.forms import flash_errors
24
+
25
+
26
+ dirpath = os.path.dirname(os.path.abspath(__file__))
27
+ module_info = {}
28
+
29
+ with open(dirpath + "/info.json") as f:
30
+ module_info = json.load(f)
31
+
32
+ globals()["{}_blueprint".format(module_info["module_name"])] = Blueprint(
33
+ "{}".format(module_info["module_name"]),
34
+ __name__,
35
+ template_folder="templates",
36
+ url_prefix=module_info["url_prefix"],
37
+ )
38
+
39
+ module_settings = {"module_info": module_info}
40
+
41
+ module_blueprint = globals()["{}_blueprint".format(module_info["module_name"])]
42
+
43
+
44
+ @module_blueprint.route("/")
45
+ @login_required
46
+ @admin_required
47
+ def index():
48
+ context = {}
49
+
50
+ front_themes_path = os.path.join(
51
+ current_app.config["BASE_DIR"], "static", "themes", "front"
52
+ )
53
+ all_front_info = {}
54
+ front_theme_folders = get_folders(front_themes_path)
55
+ for folder in front_theme_folders:
56
+ theme_path = os.path.join(front_themes_path, folder)
57
+ info_path = os.path.join(theme_path, "info.json")
58
+ with open(info_path) as f:
59
+ all_front_info[folder] = json.load(f)
60
+
61
+ back_themes_path = os.path.join(
62
+ current_app.config["BASE_DIR"], "static", "themes", "back"
63
+ )
64
+ all_back_info = {}
65
+ back_theme_folders = get_folders(back_themes_path)
66
+ for folder in back_theme_folders:
67
+ theme_path = os.path.join(back_themes_path, folder)
68
+ info_path = os.path.join(theme_path, "info.json")
69
+ with open(info_path) as f:
70
+ all_back_info[folder] = json.load(f)
71
+
72
+ active_front_theme = get_setting("ACTIVE_FRONT_THEME")
73
+ active_back_theme = get_setting("ACTIVE_BACK_THEME")
74
+
75
+ context.update(
76
+ {
77
+ "all_front_info": all_front_info,
78
+ "all_back_info": all_back_info,
79
+ "active_front_theme": active_front_theme,
80
+ "active_back_theme": active_back_theme,
81
+ }
82
+ )
83
+ context.update(module_settings)
84
+
85
+ return render_template(
86
+ "{}/index.html".format(module_info["module_name"]), **context
87
+ )
88
+
89
+
90
+ @module_blueprint.route("/activate/front/<theme_name>")
91
+ @login_required
92
+ @admin_required
93
+ def activate_front_theme(theme_name):
94
+ set_setting("ACTIVE_FRONT_THEME", theme_name)
95
+
96
+ # with app.app_context():
97
+
98
+ # current_app.jinja_loader,
99
+ # print(current_app.jinja_loader.list_templates())
100
+ return redirect(url_for("{}.index".format(module_info["module_name"])))
101
+
102
+
103
+ @module_blueprint.route("/activate/back/<theme_name>")
104
+ @login_required
105
+ @admin_required
106
+ def activate_back_theme(theme_name):
107
+ set_setting("ACTIVE_BACK_THEME", theme_name)
108
+
109
+ # with app.app_context():
110
+
111
+ # current_app.jinja_loader,
112
+ # print(current_app.jinja_loader.list_templates())
113
+ return redirect(url_for("{}.index".format(module_info["module_name"])))
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.1
2
+ Name: shopyo_theme
3
+ Version: 1.0.1
4
+ Summary: Module for managing settings in shopyo
5
+ Author-email: Abdur-Rahmaan Janhangeer <arj.python@gmail.com>
6
+ Project-URL: Homepage, https://github.com/shopyo/shopyo
7
+ Project-URL: Bug Tracker, https://github.com/shopyo/shopyo/issues
8
+ Keywords: shopyo
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Requires-Dist: shopyo
14
+ Requires-Dist: shopyo_settings
@@ -0,0 +1,14 @@
1
+ pyproject.toml
2
+ shopyo_theme/__init__.py
3
+ shopyo_theme/forms.py
4
+ shopyo_theme/helpers.py
5
+ shopyo_theme/info.json
6
+ shopyo_theme/models.py
7
+ shopyo_theme/view.py
8
+ shopyo_theme.egg-info/PKG-INFO
9
+ shopyo_theme.egg-info/SOURCES.txt
10
+ shopyo_theme.egg-info/dependency_links.txt
11
+ shopyo_theme.egg-info/requires.txt
12
+ shopyo_theme.egg-info/top_level.txt
13
+ shopyo_theme/templates/shopyo_theme/index.html
14
+ shopyo_theme/templates/shopyo_theme/blocks/sidebar.html
@@ -0,0 +1,2 @@
1
+ shopyo
2
+ shopyo_settings
@@ -0,0 +1,2 @@
1
+ dist
2
+ shopyo_theme