platzky 0.2.12__tar.gz → 0.2.15__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.
- {platzky-0.2.12 → platzky-0.2.15}/PKG-INFO +2 -2
- {platzky-0.2.12 → platzky-0.2.15}/platzky/db/db.py +2 -4
- {platzky-0.2.12 → platzky-0.2.15}/platzky/db/graph_ql_db.py +34 -12
- {platzky-0.2.12 → platzky-0.2.15}/platzky/db/json_db.py +5 -3
- {platzky-0.2.12 → platzky-0.2.15}/platzky/platzky.py +1 -1
- platzky-0.2.15/platzky/plugin_loader.py +81 -0
- {platzky-0.2.12 → platzky-0.2.15}/pyproject.toml +1 -1
- platzky-0.2.12/platzky/plugin_loader.py +0 -39
- {platzky-0.2.12 → platzky-0.2.15}/README.md +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/__init__.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/blog/__init__.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/blog/blog.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/blog/comment_form.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/config.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/db/__init__.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/db/db_loader.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/db/google_json_db.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/db/json_file_db.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/locale/en/LC_MESSAGES/messages.po +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/locale/pl/LC_MESSAGES/messages.po +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/models.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/plugins/google-tag-manager/entrypoint.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/plugins/redirections/entrypoint.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/plugins/sendmail/entrypoint.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/seo/seo.py +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/static/blog.css +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/404.html +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/base.html +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/blog.html +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/body_meta.html +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/feed.xml +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/head_meta.html +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/home.html +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/page.html +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/post.html +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/robots.txt +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/templates/sitemap.xml +0 -0
- {platzky-0.2.12 → platzky-0.2.15}/platzky/www_handler.py +0 -0
|
@@ -49,7 +49,7 @@ class DB(ABC):
|
|
|
49
49
|
pass
|
|
50
50
|
|
|
51
51
|
@abstractmethod
|
|
52
|
-
def
|
|
52
|
+
def get_menu_items_in_lang(self, lang) -> list[MenuItem]:
|
|
53
53
|
pass
|
|
54
54
|
|
|
55
55
|
@abstractmethod
|
|
@@ -69,9 +69,7 @@ class DB(ABC):
|
|
|
69
69
|
pass
|
|
70
70
|
|
|
71
71
|
@abstractmethod
|
|
72
|
-
def get_logo_url(
|
|
73
|
-
self,
|
|
74
|
-
) -> str: # TODO provide alternative text along with the URL of logo
|
|
72
|
+
def get_logo_url(self) -> str: # TODO provide alternative text along with the URL of logo
|
|
75
73
|
pass
|
|
76
74
|
|
|
77
75
|
@abstractmethod
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
from gql import Client, gql
|
|
5
5
|
from gql.transport.aiohttp import AIOHTTPTransport
|
|
6
|
+
from gql.transport.exceptions import TransportQueryError
|
|
6
7
|
from pydantic import Field
|
|
7
8
|
|
|
8
9
|
from ..models import Color, Post
|
|
@@ -99,18 +100,39 @@ class GraphQL(DB):
|
|
|
99
100
|
|
|
100
101
|
return [Post.model_validate(_standarize_post(post)) for post in raw_ql_posts]
|
|
101
102
|
|
|
102
|
-
def
|
|
103
|
-
menu_items =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
103
|
+
def get_menu_items_in_lang(self, lang):
|
|
104
|
+
menu_items = []
|
|
105
|
+
try:
|
|
106
|
+
menu_items_with_lang = gql(
|
|
107
|
+
"""
|
|
108
|
+
query MyQuery($lang: Lang!) {
|
|
109
|
+
menuItems(where: {language: $lang}, stage: PUBLISHED){
|
|
110
|
+
name
|
|
111
|
+
url
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
"""
|
|
115
|
+
)
|
|
116
|
+
menu_items = self.client.execute(
|
|
117
|
+
menu_items_with_lang, variable_values={"language": lang}
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# TODO remove try except block after bumping up version
|
|
121
|
+
# now it's backwards compatible with older versions
|
|
122
|
+
except TransportQueryError:
|
|
123
|
+
menu_items_without_lang = gql(
|
|
124
|
+
"""
|
|
125
|
+
query MyQuery {
|
|
126
|
+
menuItems(stage: PUBLISHED){
|
|
127
|
+
name
|
|
128
|
+
url
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
"""
|
|
132
|
+
)
|
|
133
|
+
menu_items = self.client.execute(menu_items_without_lang)
|
|
134
|
+
|
|
135
|
+
return menu_items["menuItems"]
|
|
114
136
|
|
|
115
137
|
def get_post(self, slug):
|
|
116
138
|
post = gql(
|
|
@@ -56,9 +56,11 @@ class Json(DB):
|
|
|
56
56
|
page = Post.model_validate(next(list_of_pages))
|
|
57
57
|
return page
|
|
58
58
|
|
|
59
|
-
def
|
|
60
|
-
menu_items_raw = self._get_site_content().get("menu_items",
|
|
61
|
-
|
|
59
|
+
def get_menu_items_in_lang(self, lang) -> list[MenuItem]:
|
|
60
|
+
menu_items_raw = self._get_site_content().get("menu_items", {})
|
|
61
|
+
items_in_lang = menu_items_raw.get(lang, {})
|
|
62
|
+
|
|
63
|
+
menu_items_list = [MenuItem.model_validate(x) for x in items_in_lang]
|
|
62
64
|
return menu_items_list
|
|
63
65
|
|
|
64
66
|
def get_posts_by_tag(self, tag, lang):
|
|
@@ -107,7 +107,7 @@ def create_engine(config: Config, db) -> Engine:
|
|
|
107
107
|
"current_lang_country": country,
|
|
108
108
|
"current_language": locale,
|
|
109
109
|
"url_link": url_link,
|
|
110
|
-
"menu_items": app.db.
|
|
110
|
+
"menu_items": app.db.get_menu_items_in_lang(locale),
|
|
111
111
|
"logo_url": app.db.get_logo_url(),
|
|
112
112
|
"favicon_url": app.db.get_favicon_url(),
|
|
113
113
|
"font": app.db.get_font(),
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import importlib.util
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from os.path import abspath, dirname
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PluginError(Exception):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# TODO remove find_local_plugin after all plugins will be extracted
|
|
15
|
+
def find_local_plugin(plugin_name):
|
|
16
|
+
"""Find plugin by name and return it as module.
|
|
17
|
+
:param plugin_name: name of plugin to find
|
|
18
|
+
:return: module of plugin
|
|
19
|
+
"""
|
|
20
|
+
plugins_dir = os.path.join(dirname(abspath(__file__)), "plugins")
|
|
21
|
+
module_name = plugin_name.removesuffix(".py")
|
|
22
|
+
spec = importlib.util.spec_from_file_location(
|
|
23
|
+
module_name, os.path.join(plugins_dir, plugin_name, "entrypoint.py")
|
|
24
|
+
)
|
|
25
|
+
assert spec is not None
|
|
26
|
+
plugin = importlib.util.module_from_spec(spec)
|
|
27
|
+
sys.modules[module_name] = plugin
|
|
28
|
+
assert spec.loader is not None
|
|
29
|
+
spec.loader.exec_module(plugin)
|
|
30
|
+
return plugin
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def find_installed_plugin(plugin_name):
|
|
34
|
+
"""Find plugin by name and return it as module.
|
|
35
|
+
:param plugin_name: name of plugin to find
|
|
36
|
+
:raises PluginError: if plugin cannot be imported
|
|
37
|
+
:return: module of plugin
|
|
38
|
+
"""
|
|
39
|
+
try:
|
|
40
|
+
return importlib.import_module(f"platzky_{plugin_name}")
|
|
41
|
+
except ImportError as e:
|
|
42
|
+
raise PluginError(
|
|
43
|
+
f"Plugin {plugin_name} not found. Ensure it's installed and follows "
|
|
44
|
+
f"the 'platzky_<plugin_name>' naming convention"
|
|
45
|
+
) from e
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def find_plugin(plugin_name):
|
|
49
|
+
"""Find plugin by name and return it as module.
|
|
50
|
+
:param plugin_name: name of plugin to find
|
|
51
|
+
:raises PluginError: if plugin cannot be found or imported
|
|
52
|
+
:return: module of plugin
|
|
53
|
+
"""
|
|
54
|
+
plugin = None
|
|
55
|
+
try:
|
|
56
|
+
plugin = find_local_plugin(plugin_name)
|
|
57
|
+
except FileNotFoundError:
|
|
58
|
+
logger.info(f"Local plugin {plugin_name} not found, trying installed version")
|
|
59
|
+
plugin = find_installed_plugin(plugin_name)
|
|
60
|
+
|
|
61
|
+
return plugin
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def plugify(app):
|
|
65
|
+
"""Load plugins and run their entrypoints.
|
|
66
|
+
:param app: Flask app
|
|
67
|
+
:return: Flask app
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
plugins_data = app.db.get_plugins_data()
|
|
71
|
+
|
|
72
|
+
for plugin_data in plugins_data:
|
|
73
|
+
plugin_config = plugin_data["config"]
|
|
74
|
+
plugin_name = plugin_data["name"]
|
|
75
|
+
try:
|
|
76
|
+
plugin = find_plugin(plugin_name)
|
|
77
|
+
plugin.process(app, plugin_config)
|
|
78
|
+
except Exception as e:
|
|
79
|
+
raise PluginError(f"Error processing plugin {plugin_name}: {e}") from e
|
|
80
|
+
|
|
81
|
+
return app
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import importlib.util
|
|
2
|
-
import os
|
|
3
|
-
import sys
|
|
4
|
-
from os.path import abspath, dirname
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def find_plugin(plugin_name):
|
|
8
|
-
"""Find plugin by name and return it as module.
|
|
9
|
-
:param plugin_name: name of plugin to find
|
|
10
|
-
:return: module of plugin
|
|
11
|
-
"""
|
|
12
|
-
plugins_dir = os.path.join(dirname(abspath(__file__)), "plugins")
|
|
13
|
-
module_name = plugin_name.removesuffix(".py")
|
|
14
|
-
spec = importlib.util.spec_from_file_location(
|
|
15
|
-
module_name, os.path.join(plugins_dir, plugin_name, "entrypoint.py")
|
|
16
|
-
)
|
|
17
|
-
assert spec is not None
|
|
18
|
-
plugin = importlib.util.module_from_spec(spec)
|
|
19
|
-
sys.modules[module_name] = plugin
|
|
20
|
-
assert spec.loader is not None
|
|
21
|
-
spec.loader.exec_module(plugin)
|
|
22
|
-
return plugin
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def plugify(app):
|
|
26
|
-
"""Load plugins and run their entrypoints.
|
|
27
|
-
:param app: Flask app
|
|
28
|
-
:return: Flask app
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
plugins_data = app.db.get_plugins_data()
|
|
32
|
-
|
|
33
|
-
for plugin_data in plugins_data:
|
|
34
|
-
plugin_config = plugin_data["config"]
|
|
35
|
-
plugin_name = plugin_data["name"]
|
|
36
|
-
plugin = find_plugin(plugin_name)
|
|
37
|
-
plugin.process(app, plugin_config)
|
|
38
|
-
|
|
39
|
-
return app
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|