tempest_fastapi_sdk.ui.pages¶
Páginas: uma classe por tela, composta de componentes.
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: |
stylesheets |
ClassVar[Sequence[str]]
|
Stylesheet URLs the
document links, in order. Read by
:func: |
head |
ClassVar[str]
|
Raw markup appended to the document head
(favicon, meta tags). Read by
:func: |
title_suffix |
ClassVar[str]
|
Appended to :attr: |
Example
document_title
¶
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: |
body
¶
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
¶
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: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Widget |
Widget
|
The wrapped widget tree. |
render
¶
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
|
|
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 |
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_error
classmethod
¶
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 |
Self
|
attr: |
body
¶
Compose the error body.
Returns:
| Name | Type | Description |
|---|---|---|
Widget |
Widget
|
A |
Widget
|
the message in an error :class: |