joop.web.components¶
Useful components for web development. It includes a base class AlpineTableComponent for generating AlpineJS-powered
tables based on Pydantic or SQLModel models.
The module also defines data access object (DAO) classes for handling row data.
Classes
|
A reusable component for rendering tables using Alpine.js and HTML templates. |
Implementation pending. |
|
|
Implementation pending. |
Implementation pending. |
- class joop.web.components.AlpineTableComponent(j_env: Environment | None = None, parent: Component | None = None)[source]¶
Bases:
HTMLComponentA reusable component for rendering tables using Alpine.js and HTML templates.
- _template_location¶
Path to the HTML template for the table.
- Type:
str
- _use_prefix_template¶
Determines whether to use a prefixed template directory.
- Type:
bool
- _row_type¶
Specifies the type of row data to be used in the table.
- Type:
Type[MetaRowDAO]
- class Data(rows: Iterable[MetaRowDAO], table_headers: Any)[source]¶
Bases:
DataRepresents the data structure for the AlpineTableComponent.
- rows¶
The rows of data to be displayed in the table.
- Type:
Iterable[MetaRowDAO]
- table_headers¶
The headers of the table, derived from the row type.
- Type:
Any
- _row_type¶
The type of row data used in the table.
- __init__(rows: Iterable[MetaRowDAO], table_headers: Any) None¶
- classmethod from_inputs(inputs: Inputs) Data[source]¶
Create a Data instance from the provided inputs.
- Parameters:
inputs (AlpineTableComponent.Inputs) – The input data for the table.
- Returns:
An instance of the Data class with initialized values.
- Return type:
- rows: Iterable[MetaRowDAO]¶
- table_headers: Any¶
- class Inputs[source]¶
Bases:
InputsRepresents the input data structure for the AlpineTableComponent. Extend this class to define specific input fields for the table.
- __init__() None¶
- class SubComponents[source]¶
Bases:
SubComponentsRepresents subcomponents of the AlpineTableComponent. Extend this class to define specific subcomponents.
- __init__() None¶
- property get_all: dict[str, Component]¶
Retrieve all subcomponents as a dictionary.
- Returns:
A dictionary where keys are subcomponent names and values are the subcomponent instances.
- Return type:
dict[str, Component]
- get_rendered() dict[str, str]¶
Return the rendered HTML output of all subcomponents.
This method ensures that all subcomponents are rendered and returns their HTML output as a dictionary.
- Returns:
A dictionary where keys are subcomponent names and values are their rendered HTML output.
- Return type:
dict[str, str]
- render()¶
Render all subcomponents and store their HTML output.
This method iterates through all subcomponents, renders each one, and stores the resulting HTML in a dictionary.
- __init__(j_env: Environment | None = None, parent: Component | None = None)¶
Initialize the HTMLComponent with a Jinja2 environment and an optional parent component.
- Parameters:
j_env (Optional[jinja2.Environment]) – The Jinja2 environment to use for rendering.
parent (Optional[Component]) – The parent component, if any.
- render(as_subcomponent: bool = False, **kwargs) str¶
Render the component as a string, optionally as a subcomponent.
This method prepares the component for rendering, loads the template, and renders the HTML output using the provided data and subcomponents.
- Parameters:
as_subcomponent (bool) – Whether to render the component as a subcomponent.
**kwargs – Additional keyword arguments for rendering.
- Returns:
The rendered HTML output.
- Return type:
str
- subs: SubComponents¶
- class joop.web.components.MetaRowDAO[source]¶
Bases:
DAOImplementation pending. A base Data Access Object (DAO) class for handling row data. This class can be extended to implement specific data access logic.
- classmethod get_model_fields() List[str]¶
Get the names of all fields defined in the _modeltype.
- Returns:
A list of field names.
- Return type:
List[str]
- Raises:
TypeError – If _modeltype is not a subclass of pydantic.BaseModel.
- property model: BaseModel¶
- to_dict() dict¶
Convert the underlying model to a dictionary, using aliases for field names.
- Returns:
A dictionary representation of the model with aliases as keys.
- Return type:
dict
- Raises:
ValueError – If no model is set for this DAO instance.
TypeError – If the model does not have Pydantic fields.
- class joop.web.components.RowDAO[source]¶
Bases:
MetaRowDAOImplementation pending. A concrete implementation of MetaRowDAO for handling generic row data.
- classmethod get_model_fields() List[str]¶
Get the names of all fields defined in the _modeltype.
- Returns:
A list of field names.
- Return type:
List[str]
- Raises:
TypeError – If _modeltype is not a subclass of pydantic.BaseModel.
- property model: BaseModel¶
- to_dict() dict¶
Convert the underlying model to a dictionary, using aliases for field names.
- Returns:
A dictionary representation of the model with aliases as keys.
- Return type:
dict
- Raises:
ValueError – If no model is set for this DAO instance.
TypeError – If the model does not have Pydantic fields.
- class joop.web.components.SQLRowDAO[source]¶
Bases:
MetaRowDAOImplementation pending. A concrete implementation of MetaRowDAO for handling SQL-based row data.
- classmethod get_model_fields() List[str]¶
Get the names of all fields defined in the _modeltype.
- Returns:
A list of field names.
- Return type:
List[str]
- Raises:
TypeError – If _modeltype is not a subclass of pydantic.BaseModel.
- property model: BaseModel¶
- to_dict() dict¶
Convert the underlying model to a dictionary, using aliases for field names.
- Returns:
A dictionary representation of the model with aliases as keys.
- Return type:
dict
- Raises:
ValueError – If no model is set for this DAO instance.
TypeError – If the model does not have Pydantic fields.