fastlifeweb 0.4.0__py3-none-any.whl → 0.4.1__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.
@@ -4,7 +4,7 @@ action=None,
4
4
  hx_post=None,
5
5
  class_="space-y-4 md:space-y-6"
6
6
  #}
7
- <form class="{{attrs.class or class_}}" {% if hx_post is not none %}hx-post="{{hx_post}}" {% endif %}{% if action is not
7
+ <form class="{{attrs.class or class_}}" {% if hx_post is not none %}hx-post="{% if hx_post is not true %}{{hx_post}}{% endif%}" {% endif %}{% if action is not
8
8
  none %}action="{{action}}" {% endif %}{% if method %}method="{{method}}" {% endif %}>
9
9
  <CsrfToken />
10
10
  {{ content }}
@@ -1,6 +1,7 @@
1
1
  {# def
2
2
  name,
3
3
  id,
4
+ multiple=False,
4
5
  class_="""
5
6
  bg-neutral-50
6
7
  block
@@ -22,6 +23,6 @@ dark:text-white
22
23
  """
23
24
  #}
24
25
 
25
- <select name="{{name}}" id="{{id}}" class="{{attrs.class or class_}}">
26
+ <select name="{{name}}" id="{{id}}" class="{{attrs.class or class_}}" {% if multiple %}multiple{% endif %}>
26
27
  {{- content -}}
27
28
  </select>
@@ -1,5 +1,5 @@
1
1
  import abc
2
- from typing import Any, Mapping, Type
2
+ from typing import Any, Mapping, Optional, Type
3
3
 
4
4
  from fastapi import Request
5
5
  from markupsafe import Markup
@@ -11,8 +11,21 @@ class AbstractTemplateRenderer(abc.ABC):
11
11
  """Used to buid pydantic form"""
12
12
 
13
13
  @abc.abstractmethod
14
- def render_template(self, template: str, **params: Any) -> str:
15
- ...
14
+ def render_template(
15
+ self,
16
+ template: str,
17
+ *,
18
+ globals: Optional[Mapping[str, Any]] = None,
19
+ **params: Any,
20
+ ) -> str:
21
+ """
22
+ Render the given template with the given params.
23
+
24
+ While rendering templates, the globals parameter is keps by the instantiated
25
+ renderer and sent to every rendering made by the request.
26
+ This is used by the pydantic form method that will render other templates
27
+ for the request.
28
+ """
16
29
 
17
30
  @abc.abstractmethod
18
31
  def pydantic_form(
@@ -1,4 +1,4 @@
1
- from typing import TYPE_CHECKING, Any, Mapping, Optional, Sequence, Type
1
+ from typing import TYPE_CHECKING, Any, Mapping, MutableMapping, Optional, Sequence, Type
2
2
 
3
3
  from fastapi import Request
4
4
  from jinjax.catalog import Catalog
@@ -41,6 +41,7 @@ class JinjaxRenderer(AbstractTemplateRenderer):
41
41
  self.request = request
42
42
  self.csrf_token_name = csrf_token_name
43
43
  self.form_data_model_prefix = form_data_model_prefix
44
+ self.globals: MutableMapping[str, Any] = {}
44
45
 
45
46
  def build_globals(self) -> Mapping[str, Any]:
46
47
  return {
@@ -50,9 +51,18 @@ class JinjaxRenderer(AbstractTemplateRenderer):
50
51
  "value": self.request.scope.get(self.csrf_token_name, ""),
51
52
  },
52
53
  "pydantic_form": self.pydantic_form,
54
+ **self.globals,
53
55
  }
54
56
 
55
- def render_template(self, template: str, **params: Any) -> str:
57
+ def render_template(
58
+ self,
59
+ template: str,
60
+ *,
61
+ globals: Optional[Mapping[str, Any]] = None,
62
+ **params: Any,
63
+ ) -> str:
64
+ if globals:
65
+ self.globals.update(globals)
56
66
  return self.catalog.render( # type: ignore
57
67
  template, __globals=self.build_globals(), **params
58
68
  )
@@ -31,4 +31,6 @@ class ModelWidget(Widget[Sequence[Widget[Any]]]):
31
31
  "widget": self,
32
32
  "children_widget": children_widget,
33
33
  }
34
- return Markup(renderer.render_template(self.get_template(), **kwargs))
34
+ return Markup(
35
+ renderer.render_template(self.get_template(), globals=None, **kwargs)
36
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastlifeweb
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: High-level web framework
5
5
  Home-page: https://github.com/mardiros/fastlife
6
6
  License: BSD-derived
@@ -20,7 +20,7 @@ fastlife/templates/A.jinja,sha256=q71nu4Rq874LG6SykCKv8W-EZeX13NMF0AsLc9FFAP0,67
20
20
  fastlife/templates/Button.jinja,sha256=535UIK4Prunj4f0YZXBmCI0rfOiTr5GJTQkM0XDmtNA,1137
21
21
  fastlife/templates/Checkbox.jinja,sha256=EbKJ9KmfexegcocxeMtoG1kt-x4bP8Tq3odh8prbJoQ,366
22
22
  fastlife/templates/CsrfToken.jinja,sha256=X2-H0VmukyUV448blh9M8rhr_gN82ar51TnRAwfV3OY,59
23
- fastlife/templates/Form.jinja,sha256=cfXWtFWCcnxdIOayR3_XWoY1PpQATiyQDqkY0Vg91g0,329
23
+ fastlife/templates/Form.jinja,sha256=h8Y2yrlrTRuLnwqCTDv8eeFgaej2eQiXDvFOx5eEcGg,367
24
24
  fastlife/templates/H1.jinja,sha256=fetjIhZvgw5gm6xJhl_-cnHvrPwuLYE4S1rVYgbqNl8,196
25
25
  fastlife/templates/H2.jinja,sha256=z022lvv3PO_g-ZxWuAiKmBOaFZ3u8Kbzd0jkuWNsOS0,196
26
26
  fastlife/templates/H3.jinja,sha256=BmSznvHOCAT8569hf-lOh0qlK3yHAPdO3KCOLD7BaPE,195
@@ -33,7 +33,7 @@ fastlife/templates/Label.jinja,sha256=m71vGDUi2HzzA5d9L3TQhdEXYKHcp6LXP6PE0-bx44
33
33
  fastlife/templates/Option.jinja,sha256=YlgBayJj94kSXK0mlGkMxTmHjTBr8T-UzvQmTcANK0Q,121
34
34
  fastlife/templates/P.jinja,sha256=xEcHIv9dJRpELu_SdqQcftvKrU8z1i_BHTEVO5Mu5dU,164
35
35
  fastlife/templates/Radio.jinja,sha256=51I5n1yjWQ_uLZfzuUUf3C8ngo-KT4dPw29-pjP9uSU,723
36
- fastlife/templates/Select.jinja,sha256=6Rw9A51JbSTprgNLz8A8E_UKfsLFf26eqdhwLnaMms4,427
36
+ fastlife/templates/Select.jinja,sha256=GoK2oh4Jl5dAfL2wN718RCwtHaQIslzDCN_nwy6a9oY,480
37
37
  fastlife/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
38
  fastlife/templates/pydantic_form/Boolean.jinja,sha256=XE3NM4vhwQwRUIbjv10t9dI70MzWhicyQ_l6FAOs8-k,298
39
39
  fastlife/templates/pydantic_form/Dropdown.jinja,sha256=JBkQp7LYtz6vvW6MyAXyW-6UDZ_xY0Fgd4mpDCQA-wM,500
@@ -47,15 +47,15 @@ fastlife/templates/pydantic_form/Widget.jinja,sha256=8raoMjtO4ARBfbz8EG-HKT112Kk
47
47
  fastlife/templating/__init__.py,sha256=QdrTmxt-K7UcJ_o9LY1n-QZAvk5foct5MNFt02zXr2w,234
48
48
  fastlife/templating/binding.py,sha256=n-MDg98Bne49BmWWWCopZsI6ef7h6PIdcszM_pRutYA,1378
49
49
  fastlife/templating/renderer/__init__.py,sha256=UJUX3T9VYjPQUhS5Enz3P6OtwftimKoGGpoQEpewVFA,181
50
- fastlife/templating/renderer/abstract.py,sha256=eS4ArmR2hc5-svrzDbRz7eeXpUbXf7wklPZT6VDsgVM,818
51
- fastlife/templating/renderer/jinjax.py,sha256=y-CN5qvAj86zKQIj6nUtNw_WyGqH5b9Je9Ro3R9ZT1I,3206
50
+ fastlife/templating/renderer/abstract.py,sha256=ksWrz25bmsN4MQJK08OYzoZfiYvAg39Z1DtjxyDDe84,1251
51
+ fastlife/templating/renderer/jinjax.py,sha256=bgHgu6VLA4S8fS7Evu68iPaODdev6v0s6Z79TX8c6Mo,3458
52
52
  fastlife/templating/renderer/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
53
  fastlife/templating/renderer/widgets/base.py,sha256=_MMtrhYvtQgX1EQNku0NSBYwhCDvQ5y8TjnCC2b4CAw,2769
54
54
  fastlife/templating/renderer/widgets/boolean.py,sha256=bk9bExUDp73is6tvbpC28ploIVjyMecFsxPN8NxnOd8,468
55
55
  fastlife/templating/renderer/widgets/dropdown.py,sha256=o3BfD9gDiRPsCPB93xCZSYRo50LRAb_tZOmK4x7zkzY,901
56
56
  fastlife/templating/renderer/widgets/factory.py,sha256=uEYaxHYygLQ-5eWWjsOlvPM6GmhHW7Nu_w-1l2HRihA,10335
57
57
  fastlife/templating/renderer/widgets/hidden.py,sha256=2fsbTQKsACV0JVYpCjXaQAV7VnQTIBPCi4lJPdWCRHc,308
58
- fastlife/templating/renderer/widgets/model.py,sha256=obZNgUiTWsMf24ge-KPSay7S3rkFn3kdQlEBbR-r-14,950
58
+ fastlife/templating/renderer/widgets/model.py,sha256=L7tdmRj0cetM_UusaD2zk5YJtIGBYizCMBKQzFyN_Ko,986
59
59
  fastlife/templating/renderer/widgets/sequence.py,sha256=x6o1L_hOh3WRlW16ZQaeO6H_qtnIitALuK-w7ck0RAw,1347
60
60
  fastlife/templating/renderer/widgets/text.py,sha256=mlW8LrRmj-aEMp8QzZOURhns6mfbV7jsOMQrsYZcU3Q,819
61
61
  fastlife/templating/renderer/widgets/union.py,sha256=GntHssMjcgpD6S5h0JVr9_aWy3pSbMhYZ9QU-ugBH-Y,1689
@@ -63,7 +63,7 @@ fastlife/testing/__init__.py,sha256=KgTlRI0g8z7HRpL7mD5QgI__LT9Y4QDSzKMlxJG3wNk,
63
63
  fastlife/testing/testclient.py,sha256=JhWgruKDeIn0QFmEAXKhUXXsZpTpPi_JWIHhWbWIXg0,16404
64
64
  fastlife/views/__init__.py,sha256=nn4B_8YTbTmhGPvSd20yyKK_9Dh1Pfh_Iq7z6iK8-CE,154
65
65
  fastlife/views/pydantic_form.py,sha256=TyZbVfhOGy3en1a7o4wcRp11War7sqVHxyEjOsRMht0,1092
66
- fastlifeweb-0.4.0.dist-info/LICENSE,sha256=F75xSseSKMwqzFj8rswYU6NWS3VoWOc_gY3fJYf9_LI,1504
67
- fastlifeweb-0.4.0.dist-info/METADATA,sha256=w-g1uz8vo-bHjLyfqKzeQI6tZL2pJEJPaXSMp4X4-RY,1833
68
- fastlifeweb-0.4.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
69
- fastlifeweb-0.4.0.dist-info/RECORD,,
66
+ fastlifeweb-0.4.1.dist-info/LICENSE,sha256=F75xSseSKMwqzFj8rswYU6NWS3VoWOc_gY3fJYf9_LI,1504
67
+ fastlifeweb-0.4.1.dist-info/METADATA,sha256=yGbsMj4GuWSO4lRUXOfE01wTMS2KYfMh04qBpu7iL1s,1833
68
+ fastlifeweb-0.4.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
69
+ fastlifeweb-0.4.1.dist-info/RECORD,,