platzky 0.2.12__py3-none-any.whl → 0.2.15__py3-none-any.whl

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/db/db.py CHANGED
@@ -49,7 +49,7 @@ class DB(ABC):
49
49
  pass
50
50
 
51
51
  @abstractmethod
52
- def get_menu_items(self) -> list[MenuItem]:
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
platzky/db/graph_ql_db.py CHANGED
@@ -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 get_menu_items(self):
103
- menu_items = gql(
104
- """
105
- query MyQuery {
106
- menuItems(stage: PUBLISHED){
107
- name
108
- url
109
- }
110
- }
111
- """
112
- )
113
- return self.client.execute(menu_items)["menuItems"]
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(
platzky/db/json_db.py CHANGED
@@ -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 get_menu_items(self) -> list[MenuItem]:
60
- menu_items_raw = self._get_site_content().get("menu_items", [])
61
- menu_items_list = [MenuItem.model_validate(x) for x in menu_items_raw]
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):
platzky/platzky.py CHANGED
@@ -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.get_menu_items(),
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(),
platzky/plugin_loader.py CHANGED
@@ -1,10 +1,18 @@
1
1
  import importlib.util
2
+ import logging
2
3
  import os
3
4
  import sys
4
5
  from os.path import abspath, dirname
5
6
 
7
+ logger = logging.getLogger(__name__)
6
8
 
7
- def find_plugin(plugin_name):
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):
8
16
  """Find plugin by name and return it as module.
9
17
  :param plugin_name: name of plugin to find
10
18
  :return: module of plugin
@@ -22,6 +30,37 @@ def find_plugin(plugin_name):
22
30
  return plugin
23
31
 
24
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
+
25
64
  def plugify(app):
26
65
  """Load plugins and run their entrypoints.
27
66
  :param app: Flask app
@@ -33,7 +72,10 @@ def plugify(app):
33
72
  for plugin_data in plugins_data:
34
73
  plugin_config = plugin_data["config"]
35
74
  plugin_name = plugin_data["name"]
36
- plugin = find_plugin(plugin_name)
37
- plugin.process(app, plugin_config)
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
38
80
 
39
81
  return app
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: platzky
3
- Version: 0.2.12
3
+ Version: 0.2.15
4
4
  Summary: Not only blog engine
5
5
  License: MIT
6
6
  Requires-Python: >=3.10,<4.0
@@ -4,17 +4,17 @@ platzky/blog/blog.py,sha256=caBUewnwd6QrJDv20m4JDfDDjiVu7hM0AJnoTyCdwM4,3009
4
4
  platzky/blog/comment_form.py,sha256=4lkNJ_S_2DZmJBbz-NPDqahvy2Zz5AGNH2spFeGIop4,513
5
5
  platzky/config.py,sha256=M3gmZI9yI-ThgmTA4RKsAPcnJwJjcWhXipYzq3hO-Hk,2346
6
6
  platzky/db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- platzky/db/db.py,sha256=SayR69Nxs9aGMfYumLyLIH0LVLVmwiQt9WAICq59gng,2709
7
+ platzky/db/db.py,sha256=yVlLqKoKRZiGNaQmRv_8Jjk0aMkHdLgDOhPbxvG_MEs,2708
8
8
  platzky/db/db_loader.py,sha256=CuEiXxhIa4bFMm0vi7ugzm7j3WycilGRKCU6smgIImE,905
9
9
  platzky/db/google_json_db.py,sha256=IgfCER7oJ4I_WD4TjhvFFL0voUj6EfeoaVWdoEcHTdA,1499
10
- platzky/db/graph_ql_db.py,sha256=aIqRxPV-Txr5MY2-qVALby9fHyIvWgvSz2t24M9SNRI,7343
11
- platzky/db/json_db.py,sha256=AtZoTcM6S2ZHo19rxkCi4h4E4INGieZ4W6H5O2iormA,3246
10
+ platzky/db/graph_ql_db.py,sha256=yXVhYCXNexYYo8QYeiUzE05uehdkl0cuuxbLU1hFC-k,8148
11
+ platzky/db/json_db.py,sha256=Iqr2bHxd55-ajosCxXOJsJ7T0TOk45KE7oIrrKo5iSM,3313
12
12
  platzky/db/json_file_db.py,sha256=UQ8TadELmqOzj_tgNfmzhtCkDkMAgcB9vaUy0GQXUY4,1010
13
13
  platzky/locale/en/LC_MESSAGES/messages.po,sha256=WaZGlFAegKRq7CSz69dWKic-mKvQFhVvssvExxNmGaU,1400
14
14
  platzky/locale/pl/LC_MESSAGES/messages.po,sha256=sUPxMKDeEOoZ5UIg94rGxZD06YVWiAMWIby2XE51Hrc,1624
15
15
  platzky/models.py,sha256=-IIlyeLzACeTUpzuzvzJYxtT57E6wRiERoRgXJYMMtY,1502
16
- platzky/platzky.py,sha256=tqCqGp-DCeyLuUcwD8RzyZiZ40SpMtRL_mhvS2xDXnc,4896
17
- platzky/plugin_loader.py,sha256=KYLDSEd_hseAgBuSbikerU_IFx-YmcYK5UwYw7kla2E,1106
16
+ platzky/platzky.py,sha256=h4oeC3B8cxbzv-Ut7iGKvsBmRTmxDKcK-R4PzUTZ-fE,4910
17
+ platzky/plugin_loader.py,sha256=kYLaBOc8MA4b0T2yhVpSxZsX1rTxfcAnyGJCNKPGBXY,2428
18
18
  platzky/plugins/google-tag-manager/entrypoint.py,sha256=Z4npXtmCdrSuUG_ZvFdPhUZg5QcwIPGQWj9Uw9dcm8A,1021
19
19
  platzky/plugins/redirections/entrypoint.py,sha256=yoqHsRLqRALdICs5_UMSREkfEo1Lbsjj9tqEA7dsseg,1555
20
20
  platzky/plugins/sendmail/entrypoint.py,sha256=16GszfLaYhVUSuCdL4SPVKYN9-mONp-hK5ZWSiLluPo,1215
@@ -32,6 +32,6 @@ platzky/templates/post.html,sha256=GSgjIZsOQKtNx3cEbquSjZ5L4whPnG6MzRyoq9k4B8Q,1
32
32
  platzky/templates/robots.txt,sha256=2_j2tiYtYJnzZUrANiX9pvBxyw5Dp27fR_co18BPEJ0,116
33
33
  platzky/templates/sitemap.xml,sha256=iIJZ91_B5ZuNLCHsRtsGKZlBAXojOTP8kffqKLacgvs,578
34
34
  platzky/www_handler.py,sha256=pF6Rmvem1sdVqHD7z3RLrDuG-CwAqfGCti50_NPsB2w,725
35
- platzky-0.2.12.dist-info/METADATA,sha256=XWU3ZXH5SMPVsF3X38JWtuK4nykS5fm8u7EtsTFTyDc,1643
36
- platzky-0.2.12.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
37
- platzky-0.2.12.dist-info/RECORD,,
35
+ platzky-0.2.15.dist-info/METADATA,sha256=PCyQWLEQkuh0zG6giZjLMwJxtzXFh6OGM8BiK7rCgKM,1643
36
+ platzky-0.2.15.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
37
+ platzky-0.2.15.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.1
2
+ Generator: poetry-core 2.0.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any