httk.serve.web.providers¶
Small, dependency-free contracts for site-local paginated data providers.
Attributes¶
Classes¶
Provide immutable site-local context to a table provider. |
|
Describe one bounded page request passed to a table provider. |
|
Describe one table column and its presentation-only metadata. |
|
Represent one bounded page of presentation rows and opaque cursors. |
Functions¶
|
Snapshot mappings and standard containers into immutable values. |
Module Contents¶
- httk.serve.web.providers.immutable_mapping(values)[source]¶
Snapshot mappings and standard containers into immutable values.
Other leaves are preserved as-is.
- Parameters:
values (collections.abc.Mapping[str, object]) – String-keyed mapping to snapshot.
- Returns:
Mapping proxy containing immutable mappings and standard containers.
- Return type:
- class httk.serve.web.providers.ProviderContext[source]¶
Provide immutable site-local context to a table provider.
- Parameters:
route – Route containing the table widget.
widget_id – Stable identifier of the table widget on the route.
query – Request query values.
page – Page context supplied by the site.
global_data – Site-global data supplied by startup code.
- query: collections.abc.Mapping[str, str][source]¶
- global_data: collections.abc.Mapping[str, object][source]¶
- url_for(route, *, query=None)[source]¶
Build a site-local route URL without exposing the ASGI request.
- Parameters:
route (str) – Relative site route to link to.
query (collections.abc.Mapping[str, str] | None) – Optional string query values.
- Returns:
Site-local URL for the route.
- Raises:
ValueError – If the route is not a safe relative site route.
TypeError – If query keys or values are not strings.
- Return type:
- class httk.serve.web.providers.TableRequest[source]¶
Describe one bounded page request passed to a table provider.
- Parameters:
page_size – Maximum number of rows requested.
cursor – Opaque provider cursor for continuation.
revision – Optional provider revision pinned across pages.
- class httk.serve.web.providers.TableColumn[source]¶
Describe one table column and its presentation-only metadata.
- Parameters:
key – Stable row value key.
label – Accessible column label.
align – Optional horizontal alignment.
class_name – Optional whitespace-free CSS class name.
- classmethod from_value(value)[source]¶
Adapt a compact column declaration to a table column.
- Parameters:
value (Self | str | collections.abc.Mapping[str, object]) – Existing column, string key, or explicit field mapping.
- Returns:
Normalized table column.
- Raises:
TypeError – If the declaration has an unsupported shape.
ValueError – If the declaration contains unknown or invalid fields.
- Return type:
Self
- class httk.serve.web.providers.TablePage[source]¶
Represent one bounded page of presentation rows and opaque cursors.
- Parameters:
rows – Presentation-only row mappings.
columns – Table columns.
next_cursor – Opaque cursor for the next page.
previous_cursor – Opaque cursor for the previous page.
total – Optional exact total row count.
revision – Optional provider revision for stable pagination.
- columns: tuple[TableColumn, Ellipsis][source]¶
- classmethod from_rows(rows, *, columns, next_cursor=None, previous_cursor=None, total=None, revision=None)[source]¶
Construct a page while adapting compact column declarations.
- Parameters:
rows (collections.abc.Iterable[collections.abc.Mapping[str, object]]) – Presentation-only row mappings.
columns (collections.abc.Iterable[TableColumn | str | collections.abc.Mapping[str, object]]) – Column declarations.
next_cursor (str | None) – Opaque cursor for the next page.
previous_cursor (str | None) – Opaque cursor for the previous page.
total (int | None) – Optional exact total row count.
revision (str | None) – Optional provider revision for stable pagination.
- Returns:
Normalized table page.
- Return type:
Self
- classmethod from_result(value)[source]¶
Normalize a table page or equivalent explicit mapping.
- Parameters:
value (object) – Provider result to normalize.
- Returns:
Normalized table page.
- Raises:
TypeError – If the result is not a table page or mapping.
ValueError – If the mapping contains invalid fields or values.
- Return type:
Self