conjunto.htmx
¶
conjunto.htmx.HxActionButton
¶
Bases: HxButton
A renderable action button from an IActionButton instance.
| Parameters: |
|
|---|
conjunto.htmx.HxButton
¶
Render a HTMX enabled button.
| Attributes: |
|
|---|
Example
{% hx_button url="person:add" method="post" icon="plus" dialog=True css_class="btn"
conjunto.htmx.HxLink
¶
Render a hyperlink using HTMX.
| Attributes: |
|
|---|
conjunto.htmx.IHtmxComponentMixin
¶
Bases: HtmxResponseMixin
An interface Mixin that describes a component and can be rendered as plugin.
- Declare an interface for HTMX components
- Declare Implementations of that interface which also inherit from
View.
Examples:
# in your plugin's api/interfaces.py, create an interface for your view
@Interface
class IUserProfileSection(IHtmxComponentMixin, ...):
params = ["pk"]
template_name = "common/layout/profile_section.html"
...
# in your plugin's views.py
def PasswordView(IUserProfileSection, UpdateView)
...
def OtherComponentView(IUserProfileSection, TemplateView)
...
Use them in your template:
{% for plugin in components.IUserProfileSection %}
<a href="#"
hx-get="{% url component.get_url_name user.id %}"
hx-trigger="{% if component.selected %}load, {% endif %}click once"
{# hx-push-url="{{ component.name }}" #}
hx-target="#profile-content"
class="list-group-item list-group-item-action d-flex align-items-center
active">
<i class="bi bi-{{ component.icon }} me-2"></i>
{{ component.title }}
</a>
{% endfor %}
You can also inherit from other mixins, e.g. PermissionRequiredMixin, etc.
class UserprofilePasswordSection(
IUserProfileSection, PermissionRequiredMixin, TemplateView
):
name = "password"
permission_required = "..."
template_name = "my_app/password_view.html
form_kwargs_request = False
class-attribute
instance-attribute
¶
Should the evtl. attached form receive a request?
group = ''
class-attribute
instance-attribute
¶
The group this component lives under. Can be used to display group headers.
icon: str = ''
class-attribute
instance-attribute
¶
the icon name, if the component is listed in a list, and icons are used.
name: str = ''
class-attribute
instance-attribute
¶
The view name of the component. Must be unique. Used in and URLs. Can be used for HTML attributes.
params: list[str] = []
class-attribute
instance-attribute
¶
A list of params the view is using. These must then be passed when calling the view from a template, e.g. via hx-get.
title: str = ''
class-attribute
instance-attribute
¶
The title this plugin is rendered with. It's up to you how the plugin uses that title.
weight: int = 0
class-attribute
instance-attribute
¶
The weight this component is ranked like menu items. The more weight, the more the component sinks "down" in the list.
enabled()
¶
Hook for implementations to define if the component is enabled.
| Returns: |
|
|---|
get_name()
¶
Returns the component's view (machine) name.
get_title()
¶
returns the component's title.
Use it in templates like {{ component.get_title }}
get_url_name()
¶
Returns the component's url.'
Use it as {% url component.get_url ... %} in a template.
get_url_patterns()
classmethod
¶
Convenience method to add to your urls.py in an include section:
Example
url_patterns = [
path(...),
path("profile/",
include(
(IUserProfileSectionView.get_url_patterns(), "profile"),
namespace="profile"
)
),
]
# or directly add the url_patterns to the main list:
url_patterns += IUserProfileSectionView.get_url_patterns()
get_urlpattern()
¶
Calculates the urlpattern where this component is accessible.
That can be used e.g. in hx-get attributes. Returns: a URLPattern that can be used in your urls.py
conjunto.htmx.Icon
¶
Render an icon using Bootstrap 5.
| Attributes: |
|
|---|
conjunto.htmx.UseComponentMixin
¶
A mixin that can be added to a View that uses HTMX components.
This can be used if e.g. a View has tabs, or variable parts of the page
that are extended by a component. The URL is pushed automatically with the new
component as configurable GET parameter, e.g.: example.com/persons/42?tab=account
Example
class MyView(UseComponentMixin, DetailView):
components = [PersonAccountTab]
| Attributes: |
|
|---|
query_variable = 'tab'
class-attribute
instance-attribute
¶
The query variable that is used to indicate the active component.