Ir para o conteúdo

tempest_fastapi_sdk.ui.pages

Páginas: uma classe por tela, composta de componentes.

« Web, UI e utilitários


Page

Bases: Component

Typed page base.

Subclass it, declare fields, and implement :meth:body. Optionally override :meth:shell to wrap every page in a shared layout. Do not override :meth:render — it is the Component hook and already composes shell(body()) for you.

Attributes:

Name Type Description
title str

The page title. :func:tempest_fastapi_sdk.ssr.html_response derives the document <title> from it (through :meth:document_title) when no title= is passed.

stylesheets ClassVar[Sequence[str]]

Stylesheet URLs the document links, in order. Read by :func:~tempest_fastapi_sdk.ssr.html_response when its stylesheets= argument is not passed. A class attribute, not a field: set it once on a base page and every subclass inherits it.

head ClassVar[str]

Raw markup appended to the document head (favicon, meta tags). Read by :func:~tempest_fastapi_sdk.ssr.html_response when its head= argument is not passed. Inserted verbatim, so it is a class constant and never built from request data.

title_suffix ClassVar[str]

Appended to :attr:title by :meth:document_title — " · tempest-bucket" turns the page titled "Buckets" into "Buckets · tempest-bucket".

Example
from tempest_core import Text, Widget

from tempest_fastapi_sdk.ui.pages import Page


class HomePage(Page):
    user_name: str

    def body(self) -> Widget:
        return Text(content=f"Olá, {self.user_name}", tag="h1")

document_title

document_title() -> str

Return the text of the document <title>.

Override it when the document title needs more than a suffix (a counter, a prefix that depends on a field).

Returns:

Name Type Description
str str

:attr:title followed by :attr:title_suffix.

body

body() -> Widget

Return the page's main content widget tree.

Subclasses must implement this.

Returns:

Name Type Description
Widget Widget

The widget tree for the page body.

Raises:

Type Description
NotImplementedError

When a subclass does not implement it.

shell

shell(body: Widget) -> Widget

Wrap the page body in a shared layout.

The default returns body unchanged. Override in a base page to add chrome (header / nav / footer) inherited by every concrete page — :class:~tempest_fastapi_sdk.ui.layout.Shell is the ready-made frame.

Parameters:

Name Type Description Default
body Widget

The widget tree returned by :meth:body.

required

Returns:

Name Type Description
Widget Widget

The wrapped widget tree.

render

render() -> Widget

Compose the page into a single widget tree.

This is the Component render hook. Subclasses override :meth:body and :meth:shell instead of this method.

Returns:

Name Type Description
Widget Widget

shell(body()) — the fully composed page.

ErrorPage

Bases: Page

A page that states a failed request's status and message.

:func:tempest_fastapi_sdk.ssr.register_html_error_handlers renders it for a GET to an HTML route that raised. To give it the service's chrome, combine it with the service's base page — class AdminErrorPage(AdminBasePage, ErrorPage) inherits shell(), stylesheets and head from the base page and body() from this one — and pass that class as error_page=.

Attributes:

Name Type Description
title_template ClassVar[str]

The title :meth:from_error builds, formatted with status_code. Defaults to "Erro {status_code}"; set "Error {status_code}" on a subclass for an English panel.

status_code int

The HTTP status of the failure.

detail str

The message, already localized by the JSON handler when a catalog is configured. Rendered escaped.

code str | None

The machine-readable error code, when the failure carried one.

Example
from tempest_fastapi_sdk.ui.pages import ErrorPage

page = ErrorPage(
    title="Erro 404",
    status_code=404,
    detail="Bucket não encontrado.",
)

from_error classmethod

from_error(*, status_code: int, detail: str, code: str | None = None) -> Self

Build the page for a failed request.

Parameters:

Name Type Description Default
status_code int

The HTTP status of the failure.

required
detail str

The message to show.

required
code str | None

The machine-readable error code, if any.

None

Returns:

Name Type Description
Self Self

An instance of cls titled from

Self

attr:title_template.

body

body() -> Widget

Compose the error body.

Returns:

Name Type Description
Widget Widget

A <section> with the page title as heading and

Widget

the message in an error :class:Alert.