MedUX API¶
Interfaces¶
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
@Interface
class IUserProfileSection(IHTMXComponentMixin, ...):
params = ["pk"]
template_name = "core/user_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 IUserProfileSection %}
TODO implement example
{% endfor %}
You can also inherit from other mixins, e.g. PermissionRequiredMixin, etc.
class UserprofilePasswordSection(IUserProfileSection, TemplateView)
name = "password"
template_name = "my_app/password_view.html
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. Used in URLs resolution. Must be unique.
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:
Type | Description |
---|---|
bool
|
True if the component is enabled, False if not. |
get_path()
¶
Calculates the url 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
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_view_name()
¶
Returns the component's view name.
Use it as {% url mycomponent.view_name ... %}
in a template.
ILoginFormExtension
¶
Bases: IFormExtensionMixin
Hook for FormExtensions for the MedUX login form
ILoginViewExtension
¶
Bases: IViewExtensionMixin
Hook for LoginView extensions
IMenuItem
¶
An extendable and versatile MenuItem Interface
You can use that for creating menu items in a named menu: .. code-block: python
class AddUserAction(IMenuItem)
menu = "page_actions"
title = _("Add user")
url = reverse_lazy("user:delete")
icon = "user-delete"
:param menu str: The menu name where this MenuItem should be rendered. Can be any string.
This menuitem is then found in templates under the menu.<this-menu-attr>
menu.
If you don't specify a menu, "main" is used.
IUserProfileSection
¶
Bases: IHTMXComponentMixin
Plugin hook that is rendered as HTMX view in the user profile as section.
MeduxPluginAppConfig
¶
Bases: AppConfig
Common base class for all MedUX AppConfigs.
All MedUX apps' AppConfigs must inherit from this class (or must at least implement this interface).
compatibility_errors()
¶
checks for compatibility issues that can't be ignored for correct application function, and returns a list of errors.
:returns a list of error strs
compatibility_warnings()
¶
Checks for compatibility issues that can be accepted for continuing.
:return: a list of warnings
initialize()
¶
Initializes the application at setup time.
This method is called from the "initialize" management command. It should set up basic data in the database etc., and needs to be idempotent.
ModalFormViewMixin
¶
Mixin for FormViews that should live in a modal.
It relies on crispy-forms intensively, and already provides a form helper instance attribute you can use.
In your template, you should extend "common/modal-form.html", this
template uses a header
with a title
block, a body
,
and a footer
block to override, for your modal dialog. In the
footer, there is always a "Cancel" button, and as default, a "Save"
button, which you can override using the "footer" block.
When the modal pops up, the focus is set to the first visible input element.
If the form is saved successfully, it returns an empty page
and emits the event specified in success_event
on the client,
so that it can reload changed content.
modal_title: str = ''
class-attribute
instance-attribute
¶
The title of the modal form
success_event: str = ''
class-attribute
instance-attribute
¶
A Javascript event that is triggered on the client after the form is saved successfully
template_name = 'common/modal-form.html'
class-attribute
instance-attribute
¶
The default template name for the modal form. This template provides a simple modal form. You can extend it in your own templates too.
get_modal_title()
¶
UseComponentMixin
¶
A mixin that can be added to a class that uses HTMX components.
Attributes:
Name | Type | Description |
---|---|---|
components |
list[IHTMXComponentMixin]
|
a list of Interfaces that are used in the template of this
view, and can be accessed there using |