API reference¶
Views¶
View support classes and functions for htmx-views.
- class htmx_views.views.HTMXFormMixin(*args, **kwargs)[source]¶
Bases:
HTMXProcessMixinProvide additional methods to adapt FormView and friends for htmx requests as well.
- form_invalid(form)[source]¶
Look for HTMX form valid handlers.
If request.htmx is not set, then return the parent class form_invalid, otherwise look for an element specific htmx_form_invalid_<name> method, or failing that just an htmx_form_invalid meothd. Fnally, give up and return the parent form_invalid.
- Notes:
htmx_inform_valid* methods must not call super().form_valid - otherwise an infinite recursion happens!
- form_valid(form)[source]¶
Look for HTMX form valid handlers.
If request.htmx is not set, then return the parent class form_valid, otherwise look for an element specific htmx_form_valid_<name> method, or failing that just an htmx_form_valid meothd. Fnally, give up and return the parent form_valid.
- Notes:
htmx_form_valid* methods must not call super().form_valid - otherwise an infinite recursion happens!
- class htmx_views.views.HTMXProcessMixin(*args, **kwargs)[source]¶
Bases:
objectProvide versions of the htmx_`<http_verb>` methods that will delegate to trigger specific methods.
Each http verb DELETE,GET,PATCH,POST,PUT’s htmx_<verb> method will look at the request.htmx attriobute to see if htmx_<verb>_<trigger_name>, htmx_<verb>_<trigger>, htmx_<verb>_<target> is a method and then pass on to the first matching method. If no match is foumd, the http_method_not_allowed method is used instead.
- get_context_data_function(**kwargs)[source]¶
Return the first callable element-specific context handler.
- get_context_object_name(object_list)[source]¶
Get context object name being aware of htmx elements.
If the get_context_name_<element> method needs to call usper, it should set a keyword argument, _default to be True to avoid a recursive loop.
- htmx_delete(request, *args, **kwargs)[source]¶
Delegate HTMX DELETE requests.
Looks for the element that is related to the request by inspecting the request.htmx trigger_name, trigger and target attributes in turn. If no matching htmx_delete_<name> methods are found, return the method_not_allowed result instrad.
- htmx_get(request, *args, **kwargs)[source]¶
Delegate HTMX GET requests.
Looks for the element that is related to the request by inspecting the request.htmx trigger_name, trigger and target attributes in turn. If no matching htmx_get_<name> methods are found, return the method_not_allowed result instrad.
- htmx_patch(request, *args, **kwargs)[source]¶
Delegate HTMX PATCH requests.
Looks for the element that is related to the request by inspecting the request.htmx trigger_name, trigger and target attributes in turn. If no matching htmx_patch_<name> methods are found, return the method_not_allowed result instrad.
- htmx_post(request, *args, **kwargs)[source]¶
Delegate HTMX POST requests.
Looks for the element that is related to the request by inspecting the request.htmx trigger_name, trigger and target attributes in turn. If no matching htmx_post_<name> methods are found, return the method_not_allowed result instrad.
- htmx_put(request, *args, **kwargs)[source]¶
Delegate HTMX PUT requests.
Looks for the element that is related to the request by inspecting the request.htmx trigger_name, trigger and target attributes in turn. If no matching htmx_put_<name> methods are found, return the method_not_allowed result instrad.
- htmx_views.views.dispatch(self, request, *args, **kwargs)[source]¶
Dispatch method that becomes htmx aware.
If the =`htmx` request attribute is set (by django-htmx) and the method name is in either self.http_method_names or self.htmx_method_names then try to locate the method htmx_<http_verb> method and call that or else fall back to the regular <http_verb> method.
If an approrpiate method can’t be located, call self.http_method_bot_allowed for error handline.
If the htmx request attrobute is not set or is False, then fall back to the original dispatch.
Linked-select endpoint¶
Linked-select endpoint backed by the optional django-ajax-selects package.
- class htmx_views.linked_selects.LinkedSelectEndpointView(**kwargs)[source]¶
Bases:
TemplateViewReturn linked-select options from an authorised lookup.
Widgets¶
Create an htmx backed linked select widget.
- class htmx_views.widgets.HTMXSelectWidget(lookup_channel, parent=None, *args, **kwargs)[source]¶
Bases:
SelectOverride SelectWidget to allow the options to be updated on a linked change.
This uses the machinery of django-ajax-select lookups to derive the list of options, but uses htmx for the transfer mechanism.
Application configuration¶
- class htmx_views.apps.EquipmentConfig(app_name, app_module)[source]¶
Bases:
HTMXViewsConfigCompatibility name for code importing the former app config.