Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions flask_htmx/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import typing


#: True and False values for the HX-* request and response headers
HX_TRUE = "true"
HX_FALSE = "false"
Expand All @@ -14,6 +17,17 @@
"none",
]

ReSwapType = typing.Literal[
"innerHTML",
"outerHTML",
"beforebegin",
"afterbegin",
"beforeend",
"afterend",
"delete",
"none",
]

#: If you want to stop polling from a server response you can respond with the HTTP
#: response code 286 and the element will cancel the polling.
HTMX_STOP_POLLING = 286
2 changes: 1 addition & 1 deletion flask_htmx/htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class HTMX:
- https://github.com/adamchainz/django-htmx
"""

def __init__(self, app: Flask = None):
def __init__(self, app: Optional[Flask] = None):
self.app = app
if app is not None:
self.init_app(app)
Expand Down
22 changes: 14 additions & 8 deletions flask_htmx/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
from flask import Response
from flask import make_response as flask_make_response

from flask_htmx.constants import HTMX_STOP_POLLING, HX_FALSE, HX_TRUE, RESWAPS
from flask_htmx.constants import (
HTMX_STOP_POLLING,
HX_FALSE,
HX_TRUE,
RESWAPS,
ReSwapType,
)


class HTMXResponseClientRedirect(Response):
Expand Down Expand Up @@ -41,16 +47,16 @@ def _stringify(val):

def make_response(
*args: typing.Any,
location: str | dict | None = None,
push_url: str | False | None = None,
location: str | typing.Dict[str, str] | None = None,
push_url: str | typing.Literal[False] | None = None,
redirect: str | None = None,
refresh: bool = False,
replace_url: str | False | None = None,
reswap: str | None = None,
replace_url: str | typing.Literal[False] | None = None,
reswap: ReSwapType | None = None,
retarget: str | None = None,
trigger: str | dict | None = None,
trigger_after_settle: str | dict | None = None,
trigger_after_swap: str | dict | None = None,
trigger: str | typing.Dict[str, str] | None = None,
trigger_after_settle: str | typing.Dict[str, str] | None = None,
trigger_after_swap: str | typing.Dict[str, str] | None = None,
) -> Response:
"""
This function can be used as a replacement from :code:`flask.make_response` to
Expand Down