ushka.utils.flash
This module provides "flash messaging" functionality for the Ushka framework, allowing messages to be stored in the user's session and retrieved for display on the next request.
It includes a Category enum for message types and functions to store (flash)
and retrieve (get_flashed_messages) these messages.
class StrEnum(str, Enum)
Minimal backport of :class:enum.StrEnum.
class Category(StrEnum)
Represents the category or type of a flash message.
Attributes
SUCCESS | str | Indicates a successful operation ("success"). |
DANGER | str | Indicates a critical error or danger ("danger"). |
WARNING | str | Indicates a potential issue or warning ("warning"). |
INFO | str | Provides general information ("info"). |
def flash(request: Request, message: str, category: Category | str = Category.INFO) -> None
Stores a flash message in the user's session.
These messages are typically retrieved and displayed on a subsequent request, then automatically removed from the session.
Parameters
request | Request | The incoming HTTP request object, which provides access to the session. |
message | str | The content of the message to be flashed. |
category | Category or str | The category of the message (e.g., 'info', 'danger', 'success', 'warning').
Defaults to |
Returns
None |
def get_flashed_messages(request: Request, with_categories: bool = False) -> Union[List[str], List[Tuple[str, str]]]
Pops and retrieves all flashed messages from the session.
Parameters
request | Request | The request object containing the session data. |
with_categories | bool | If True, returns a list of (category, message) tuples. If False, returns only a list of messages. Defaults to False. |
Returns
list of str or list of tuple of (str, str) | The list of flashed messages. The messages are removed from the session after retrieval. |