fastlifeweb 0.26.1__py3-none-any.whl → 0.26.2__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.
CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.26.2 - Released on 2025-04-20
2
+ * Add a RedirectResponse class that is htmx friendly and P/R/G pattern friendly.
3
+ * Fix documentation generation.
4
+
1
5
  ## 0.26.1 - Released on 2025-04-20
2
6
  * Add new helpers for the webtestclient element.
3
7
 
fastlife/__init__.py CHANGED
@@ -2,8 +2,6 @@ from importlib import metadata
2
2
 
3
3
  __version__ = metadata.version("fastlifeweb")
4
4
 
5
- from fastapi import Response
6
- from fastapi.responses import RedirectResponse
7
5
 
8
6
  from .adapters.fastapi.form import form_model
9
7
  from .adapters.fastapi.localizer import Localizer
@@ -26,6 +24,7 @@ from .config import (
26
24
  from .domain.model.asgi import ASGIRequest, ASGIResponse
27
25
  from .domain.model.form import FormModel
28
26
  from .domain.model.request import GenericRequest
27
+ from .domain.model.response import RedirectResponse, Response
29
28
  from .domain.model.security_policy import (
30
29
  Allowed,
31
30
  Anonymous,
@@ -6,7 +6,7 @@
6
6
 
7
7
  ::
8
8
 
9
- <Form :hx-post="true">
9
+ <Form hx-post>
10
10
  <Input name="name" placeholder="Bob" />
11
11
  <Button>Submit</Button>
12
12
  </Form>
@@ -0,0 +1,40 @@
1
+ from collections.abc import Mapping
2
+ from urllib.parse import quote
3
+
4
+ from starlette.background import BackgroundTask
5
+ from starlette.datastructures import URL
6
+ from starlette.responses import Response
7
+
8
+
9
+ class RedirectResponse(Response):
10
+ """
11
+ A redirect response for Post/Redirect/Get pattern.
12
+
13
+ The starlette default value status code is 307, which means that it is used
14
+ as a way to replay the same query which is definitly not the most used case
15
+ in web applications.
16
+
17
+ This is why the redirect response here is using 303 see other which
18
+ ensure a GET request will be made for the redirection.
19
+
20
+ A new parameter hx_redirect exists in order to set the HX-Redirect header
21
+ to follow a browser redirection from an ajax query.
22
+ """
23
+
24
+ def __init__(
25
+ self,
26
+ url: str | URL,
27
+ hx_redirect: bool = False,
28
+ status_code: int = 303,
29
+ headers: Mapping[str, str] | None = None,
30
+ background: BackgroundTask | None = None,
31
+ ):
32
+ super().__init__(
33
+ content=b"", status_code=status_code, headers=headers, background=background
34
+ )
35
+ self.headers["HX-Redirect" if hx_redirect else "location"] = quote(
36
+ str(url), safe=":/%#?=@[]!$&'()*+,;"
37
+ )
38
+
39
+
40
+ __all__ = ["Response", "RedirectResponse"]
@@ -158,9 +158,14 @@ class WebTestClient:
158
158
  method = "GET"
159
159
  headers = None
160
160
  content = None
161
+ url = resp.headers.get("location")
162
+ if "HX-Redirect" in resp.headers:
163
+ # Redirection requested to the browser from an AJAX request.
164
+ url = resp.headers["HX-Redirect"]
165
+ assert url, "Redirect response without a redirection"
161
166
  return self.request(
162
167
  method=method,
163
- url=resp.headers["location"],
168
+ url=url,
164
169
  content=content,
165
170
  headers=headers,
166
171
  max_redirects=max_redirects - 1,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastlifeweb
3
- Version: 0.26.1
3
+ Version: 0.26.2
4
4
  Summary: High-level web framework
5
5
  Author-Email: Guillaume Gauvrit <guillaume@gauvr.it>
6
6
  License: MIT
@@ -1,5 +1,5 @@
1
- CHANGELOG.md,sha256=T96sQ3Cf4MXmutaDj0-js6kwr0hVzDJA9krCjrV557g,8680
2
- fastlife/__init__.py,sha256=IZ9VQvlBduZ3WjfDk05rZNdCKNxWWqPaMvG0ZWtMTpU,2489
1
+ CHANGELOG.md,sha256=NqlUm-TificrXs2dKAL5-1_6i3Eo74MRksoaa0RBS1k,8830
2
+ fastlife/__init__.py,sha256=Fe8JiQyKIN1WGagUGFct-QBW8-Ku5vXhc_7BkFUGcWk,2475
3
3
  fastlife/adapters/__init__.py,sha256=imPD1hImpgrYkvUJRhHA5kVyGAua7VbP2WGkhSWKJT8,93
4
4
  fastlife/adapters/fastapi/__init__.py,sha256=1goV1FGFP04TGyskJBLKZam4Gvt1yoAvLMNs4ekWSSQ,243
5
5
  fastlife/adapters/fastapi/form.py,sha256=csxsDI6RK-g41pMwFhaVQCLDhF7dAZzgUp-VcrC3NFY,823
@@ -49,7 +49,7 @@ fastlife/components/Button.jinja,sha256=itKU-ct45XissU33yfmTekyHsNe00fr4RQL-e9cx
49
49
  fastlife/components/Checkbox.jinja,sha256=g62A1LR8TaN60h94pE2e5l9_eMmgnhVVE9HVCQtVVMo,748
50
50
  fastlife/components/CsrfToken.jinja,sha256=mS0q-3_hAevl_waWEPaN0QAYOBzMyzl-W1PSpEHUBA0,215
51
51
  fastlife/components/Details.jinja,sha256=NtQX-V3kcp1CV1GkrMkj5fc-KHPZHshWkrhXAZ8E3ms,736
52
- fastlife/components/Form.jinja,sha256=IJhkUwp_dF-BePi8okh-sUglXP6wJvtxNd-4PUFCwTY,2089
52
+ fastlife/components/Form.jinja,sha256=p4HNIpjDLJT0oH_Vbv6_lYV0tuG_2Xu5E2vZ-yJWrT8,2081
53
53
  fastlife/components/H1.jinja,sha256=fWZtTq34qN9gwGgDF91lkypxaXvGN_OTmUY7XUHIpw0,370
54
54
  fastlife/components/H2.jinja,sha256=o7Q-oR_zDtItV5A7QWfEo_LoMw6bR44YNBDQP3ao1bg,370
55
55
  fastlife/components/H3.jinja,sha256=cZHJTVER1LVYWAwP3sR-23Ktbk9WYlLgLnr2Dz_0oqU,370
@@ -1701,6 +1701,7 @@ fastlife/domain/model/asgi.py,sha256=Cz45TZOtrh2pBVZr37aJ9jpnJH9BeNHrsvk9bq1nBc0
1701
1701
  fastlife/domain/model/csrf.py,sha256=BUiWK-S7rVciWHO1qTkM8e_KxzpF6gGC4MMJK1v6iDo,414
1702
1702
  fastlife/domain/model/form.py,sha256=JP6uumlZBYhiPxzcdxOsfsFm5BRfvkDFvlUCD6Vy8dI,3275
1703
1703
  fastlife/domain/model/request.py,sha256=HgUSnUu3q18e07y57PadN3pPQwYrIZS1YEhYkBZ_Zfg,2674
1704
+ fastlife/domain/model/response.py,sha256=Vsd2zYGGhH0D2DlfiKz1CX9OJZ_ZYoEv_-foMZpDFZo,1294
1704
1705
  fastlife/domain/model/security_policy.py,sha256=f9SLi54vvRU-KSPJ5K0unoqYpkxIyzuZjKf2Ylwf5Rg,4796
1705
1706
  fastlife/domain/model/template.py,sha256=z9oxdKme1hMPuvk7mBiKR_tuVY8TqH77aTYqMgvEGl8,876
1706
1707
  fastlife/domain/model/types.py,sha256=64jJKFAi5x0e3vr8naHU1m_as0Qy8MS-s9CG0z6K1qc,381
@@ -1730,11 +1731,11 @@ fastlife/testing/__init__.py,sha256=VpxkS3Zp3t_hH8dBiLaGFGhsvt511dhBS_8fMoFXdmU,
1730
1731
  fastlife/testing/dom.py,sha256=q2GFrHWjwKMMTR0dsP3J-rXSxojZy8rOQ-07h2gfLKA,5869
1731
1732
  fastlife/testing/form.py,sha256=diiGfVMfNt19JTNUxlnbGfcbskR3ZMpk0Y-A57vfShc,7871
1732
1733
  fastlife/testing/session.py,sha256=LEFFbiR67_x_g-ioudkY0C7PycHdbDfaIaoo_G7GXQ8,2226
1733
- fastlife/testing/testclient.py,sha256=4LLw_QchEzdcdIobtIEzCABNebzyzVPEMj1tjdXQU_Y,6984
1734
+ fastlife/testing/testclient.py,sha256=gqgHQalhrLLZ8eveN2HeuoG9ne8CwxCm-Ll4b7jo9Xo,7249
1734
1735
  fastlife/views/__init__.py,sha256=zG8gveL8e2zBdYx6_9jtZfpQ6qJT-MFnBY3xXkLwHZI,22
1735
1736
  fastlife/views/pydantic_form.py,sha256=o7EUItciAGL1OSaGNHo-3BTrYAk34GuWE7zGikjiAGY,1486
1736
- fastlifeweb-0.26.1.dist-info/METADATA,sha256=ZrtYyrVue0a2wbR9S0wALG-3COPtbvSZVKHitRfu3t4,3690
1737
- fastlifeweb-0.26.1.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
1738
- fastlifeweb-0.26.1.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
1739
- fastlifeweb-0.26.1.dist-info/licenses/LICENSE,sha256=JFWuiKYRXKKMEAsX0aZp3hBcju-HYflJ2rwJAGwbCJo,1080
1740
- fastlifeweb-0.26.1.dist-info/RECORD,,
1737
+ fastlifeweb-0.26.2.dist-info/METADATA,sha256=btOasL9jb9IiIrj9yPnrSW60e3T8Xpxy2Abu0hBBcb8,3690
1738
+ fastlifeweb-0.26.2.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
1739
+ fastlifeweb-0.26.2.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
1740
+ fastlifeweb-0.26.2.dist-info/licenses/LICENSE,sha256=JFWuiKYRXKKMEAsX0aZp3hBcju-HYflJ2rwJAGwbCJo,1080
1741
+ fastlifeweb-0.26.2.dist-info/RECORD,,