Contrib for balderhub-crud

For activating this module, you need to install the package like shown below

>>> pip install balderhub-html[crud]

Once installed you can use it.

Field Callbacks

This BalderHub project provides field callbacks for almost every normal HTML element, that is provided by this package. You can use it right away.

class balderhub.html.contrib.crud.utils.field_callbacks.BaseHtmlElemFieldCollectorCallback(html_element: HtmlElement | Callable[[CallbackElementObjectT], HtmlElement], type_convert_cb: Callable[[Any], Any] | None = None, **kwargs)

Bases: FieldCollectorCallback, ABC

Represents a base callback handler for collecting HTML elements for an associated field.

This class is used as a foundation for processing and validating HTML elements tied to fields during callback operations. It enforces type checking on the provided or generated HTML elements against a predefined list of allowed types. Subclasses are expected to specify the allowed HTML element types through the ALLOWED_HTML_ELEMENT_TYPES attribute and implement additional custom behavior as needed.

get_html_element(for_container: CallbackElementObjectT)

Retrieves an HTML element based on the provided callback object. If the stored callback is already an instance of HtmlElement, it is returned directly. Otherwise, a callback function is invoked to generate the element out of the provided element callback.

Parameters:

for_container – A callback object used to generate the HTML element if the stored callback is not directly an HtmlElement.

Returns:

The resulting HTML element from the callback or the pre-existing HtmlElement

Raises:

TypeError – If the resulting element from the callback is not of a permitted type

class balderhub.html.contrib.crud.utils.field_callbacks.BaseHtmlElemFieldFillerCallback(html_element: HtmlElement | Callable[[CallbackElementObjectT], HtmlElement], **kwargs)

Bases: FieldFillerCallback, ABC

Base class for creating callbacks for filling fields with HTML elements.

This class defines a standardized way to create callbacks that manage HTML elements used for field-filling purposes. Subclasses are expected to specify the allowed HTML element types through the ALLOWED_HTML_ELEMENT_TYPES attribute and implement additional custom behavior as needed.

get_html_element(for_container: CallbackElementObjectT)

Retrieves an HTML element based on the provided callback object. If the stored callback is already an instance of HtmlElement, it is returned directly. Otherwise, a callback function is invoked to generate the element out of the provided element callback.

Parameters:

for_container – A callback object used to generate the HTML element if the stored callback is not directly an HtmlElement.

Returns:

The resulting HTML element from the callback or the pre-existing HtmlElement

Raises:

TypeError – If the resulting element from the callback is not of a permitted type

class balderhub.html.contrib.crud.utils.field_callbacks.CheckboxCollectorFieldCallback(html_element: HtmlElement | Callable[[CallbackElementObjectT], HtmlElement], type_convert_cb: Callable[[Any], Any] | None = None, **kwargs)

Bases: BaseHtmlElemFieldCollectorCallback

Manages the collection of field values specifically for HTML checkbox input elements.

This class is designed to handle the process of collecting field values for HTML checkbox inputs by checking their state (checked or unchecked).

ALLOWED_HTML_ELEMENT_TYPES = (<class 'balderhub.html.lib.utils.components.inputs.html_checkbox_input.HtmlCheckboxInput'>,)

supports HTML elements

class balderhub.html.contrib.crud.utils.field_callbacks.CheckboxFillerFieldCallback(html_element: HtmlElement | Callable[[CallbackElementObjectT], HtmlElement], **kwargs)

Bases: BaseHtmlElemFieldFillerCallback

Handles operations related to setting and unsetting HTML checkbox input fields.

This callback class is designed to interact with HTML checkbox elements, specifically for filling in and unsetting checkbox values in a field. It ensures that the checkbox fields are filled or unset based on provided boolean values.

ALLOWED_HTML_ELEMENT_TYPES = (<class 'balderhub.html.lib.utils.components.inputs.html_checkbox_input.HtmlCheckboxInput'>,)

supports HTML elements

class balderhub.html.contrib.crud.utils.field_callbacks.InputCollectorFieldCallback(html_element: HtmlElement | Callable[[CallbackElementObjectT], HtmlElement], type_convert_cb: Callable[[Any], Any] | None = None, **kwargs)

Bases: BaseHtmlElemFieldCollectorCallback

Class responsible for collecting field values from specified HTML input elements.

This class provides a mechanism to collect data from various specified HTML input element types. It focuses on collecting the text content of the elements.

ALLOWED_HTML_ELEMENT_TYPES = (<class 'balderhub.html.lib.utils.components.inputs.html_email_input.HtmlEmailInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_month_input.HtmlMonthInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_number_input.HtmlNumberInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_search_input.HtmlSearchInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_text_input.HtmlTextInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_tel_input.HtmlTelInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_password_input.HtmlPasswordInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_url_input.HtmlUrlInput'>)

supports HTML elements

class balderhub.html.contrib.crud.utils.field_callbacks.InputFillerFieldCallback(html_element: HtmlElement | Callable[[CallbackElementObjectT], HtmlElement], **kwargs)

Bases: BaseHtmlElemFieldFillerCallback

This class is responsible for handling the process of filling and unsetting input fields for supported HTML element types. It provides functionality to interact with various kinds of HTML input elements.

ALLOWED_HTML_ELEMENT_TYPES = (<class 'balderhub.html.lib.utils.components.inputs.html_email_input.HtmlEmailInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_month_input.HtmlMonthInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_number_input.HtmlNumberInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_search_input.HtmlSearchInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_text_input.HtmlTextInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_tel_input.HtmlTelInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_password_input.HtmlPasswordInput'>, <class 'balderhub.html.lib.utils.components.inputs.html_url_input.HtmlUrlInput'>)

supports HTML elements

class balderhub.html.contrib.crud.utils.field_callbacks.SelectCollectorFieldCallback(html_element: HtmlElement | Callable[[CallbackElementObjectT], HtmlElement], type_convert_cb: Callable[[Any], Any] | None = None, **kwargs)

Bases: BaseHtmlElemFieldCollectorCallback

Callback to collect and process values from HTML select elements.

This class is used to retrieve and process values from HTML select elements in a given context.

ALLOWED_HTML_ELEMENT_TYPES = (<class 'balderhub.html.lib.utils.components.html_select_element.HtmlSelectElement'>,)

supports HTML elements

class balderhub.html.contrib.crud.utils.field_callbacks.SelectFillerFieldCallback(html_element: HtmlElement | Callable[[CallbackElementObjectT], HtmlElement], unset_value: str | None = '', **kwargs)

Bases: BaseHtmlElemFieldFillerCallback

Handles the behavior and interaction for filling and unsetting HTML select elements.

This class is designed to manage the functionality for interacting with HTML <select> elements. It fills these elements with specific values or reverts them to an unset state based on defined rules and inputs.

ALLOWED_HTML_ELEMENT_TYPES = (<class 'balderhub.html.lib.utils.components.html_select_element.HtmlSelectElement'>,)

supports HTML elements

class balderhub.html.contrib.crud.utils.field_callbacks.TextCollectorFieldCallback(html_element: HtmlElement | Callable[[CallbackElementObjectT], HtmlElement], type_convert_cb: Callable[[Any], Any] | None = None, **kwargs)

Bases: BaseHtmlElemFieldCollectorCallback

A callback class for collecting specific field values from HTML elements.

This class is designed to extract and collect text values from certain types of HTML elements as part of a data collection or transformation pipeline. It ensures compatibility with HTML elements defined in its allowed types.

Variables:

ALLOWED_HTML_ELEMENT_TYPES – Specifies the types of HTML elements that this callback supports.

ALLOWED_HTML_ELEMENT_TYPES = (<class 'balderhub.html.lib.utils.components.html_element.HtmlElement'>,)

supports HTML elements

class balderhub.html.contrib.crud.utils.field_callbacks.ValueFromUrlCollectorFieldCallback(url_schema: Url, parameter_name: str, type_convert_cb: Callable[[Any], Any] | None = None, **kwargs)

Bases: FieldCollectorCallback

This field callback expects a html page as the container object. Over this object, the callback reads the url and resolves the provided url parameter

Field Callbacks Auto-Select Functions

This package does also provide functions to auto select the correct callback based on the given html element.

balderhub.html.contrib.crud.utils.field_callbacks.get_field_collector_callback_type_for(widget_type: type[html.HtmlElement]) type[FieldCollectorCallback]

Determine and return the appropriate field collector callback type for a given widget type. The function uses the widget type to identify its corresponding field collector callback. If the widget type is not recognized, it raises an ValueError.

Parameters:

widget_type – The class type of a widget, either an HTML element or a change form fieldset field. It must be a subclass of HtmlElement.

Returns:

The corresponding field collector callback type for the given widget type.

balderhub.html.contrib.crud.utils.field_callbacks.get_field_filler_callback_type_for(widget_type: type[html.HtmlElement]) type[FieldFillerCallback]

Determines the appropriate callback type for filling fields, based on the provided html element type. The function maps specific widget types to their respective field filler callback classes. If the widget type is not recognized, it raises an ValueError.

Parameters:

widget_type – The type of widget for which the field filler callback type is to be determined. It must be a subclass of HtmlElement.

Returns:

The class type of the appropriate FieldFillerCallback for the given widget type.