Built-ins
DataviewActionDefinition
Describe an action for a dataview and its current selection.
DataviewActionContext includes the request, model, active preference,
filtered queryset, and selected IDs. Execution receives a queryset scoped
to the current view and a selection limited to accessible matching rows.
Register the definition using its ID as the key.
| Setting | Type | Default | Description |
|---|---|---|---|
id | str | Required | Stable ID used in action configuration.Minimum length: 1 |
documentation | str | '' | Markdown and tagged examples included in the generated developer reference. |
models | ModelSelector | '__all__' | Model scope. Use a Django model class, a list of classes, 'all', or a zero-argument callable returning one of those selectors. Use None or an empty list for no models. |
methods | tuple[Literal['GET', 'POST'], ...] | ('GET', 'POST') | Allowed HTTP methods. The first is used by the action button.Minimum length: 1 |
method | Optional[Literal['GET', 'POST']] | None | Legacy single-method override for existing action definitions. |
description | str | '' | The description of the action. |
label | str | None | None | Optional label for the action. |
icon | str | None | None | Optional Font Awesome icon for the action. |
shortcut | str | None | None | Optional keyboard shortcut, such as 'alt+arrowright' (Alt + Right Arrow), or a sequence like 'k then p'. |
get_button_attrs | Callable[[DataviewActionContext], dict[str, Any]] | BaseActionDefinition.<lambda> | Return additional HTML attributes for the default action button. |
get_query_params | Callable[[DataviewActionContext], ActionQueryParams] | None | None | Return query parameters for the default action button's URL. A sequence gives repeated values. Object actions add no extra parameters by default. Dataview HTMX actions use live filters and selection by default. For a custom HTMX URL, supply a callback to use its own query parameters, or return an empty mapping to leave the URL as supplied. Registered action handlers still receive their source dataview context. |
is_visible | Callable[[DataviewActionContext], bool] | BaseActionDefinition.<lambda> | Determine whether to show the action in the current context. |
execute | Callable[[DataviewActionContext], HttpResponse | StreamingHttpResponse | None] | None | None | Handler for an action request. HTML-only controls can omit it. |
success_message | str | None | None | Message shown when the handler returns no response. |
refresh_on_success | Optional[Literal['item', 'dataview']] | None | Refresh the originating record or dataview when the handler returns no response. |
render | Callable[[DataviewActionContext, Mapping[str, Any]], str] | None | None | Return an HTML fragment using the action context and surrounding template context. The template context includes the current definition under 'action'. |
requires_selection | bool | False | Show this action with selection controls and require accessible selected records. |
Count matching records
Add example-count-records to ModelViewSettings.dataview_actions to count
the records in the active search and filters.
from django.http import HttpResponse
from bloomerp.actions import DATAVIEW_ACTION_REGISTRY
from bloomerp.actions.definition import DataviewActionContext, DataviewActionDefinition
from bloomerp.utils.requests import render_message
def count_records(context: DataviewActionContext) -> HttpResponse:
'''Report the number of accessible records matching the current view.'''
count = context.queryset.count()
return render_message(context.request, f"{count} matching records", "info")
def count_button_attrs(context: DataviewActionContext) -> dict[str, str]:
'''Display the count in the action response area.'''
return {"hx-target": "#object-actions-target"}
show_count = DataviewActionDefinition(
id="example-count-records",
label="Count records",
description="Count records matching the active dataview.",
execute=count_records,
get_button_attrs=count_button_attrs,
)
DATAVIEW_ACTION_REGISTRY.register(show_count.id, show_count)Render a toolbar caption
Use render for a toolbar item that displays custom markup. This example
scopes the caption to Todo dataviews.
from collections.abc import Mapping
from typing import Any
from django.utils.html import format_html
from bloomerp.actions import DATAVIEW_ACTION_REGISTRY
from bloomerp.actions.definition import DataviewActionContext, DataviewActionDefinition
from bloomerp.models.project_management.todo import Todo
def render_caption(context: DataviewActionContext, page_context: Mapping[str, Any]) -> str:
'''Display the collection name as an escaped HTML fragment.'''
return format_html("<span>Showing {}</span>", context.model._meta.verbose_name_plural)
caption = DataviewActionDefinition(
id="example-toolbar-caption",
models=Todo,
label="Collection name",
description="Show the current model's plural name in the toolbar.",
render=render_caption,
)
DATAVIEW_ACTION_REGISTRY.register(caption.id, caption)Filter
ID filter
Edit the conditions used to select records in the dataview.
Models All models
| Field | Value |
|---|---|
icon | fa fa-filter |
shortcut | mod+1 |
requires_selection | False |
Add
ID add
Open a form to create a record in this dataview's model.
Models All models
| Field | Value |
|---|---|
icon | fa fa-plus |
shortcut | mod+2 |
requires_selection | False |
All matching records
ID bulk-all-matching
Open bulk operations for every record matching the active search and filters.
Models All models
| Field | Value |
|---|---|
icon | fa fa-filter |
requires_selection | False |
Selected records
ID bulk-selected-records
Open bulk operations for the records selected in this dataview.
Models All models
| Field | Value |
|---|---|
icon | fa fa-list-check |
requires_selection | True |
Import
ID import
Open the bulk import page for this dataview's model.
Models All models
| Field | Value |
|---|---|
icon | fa-solid fa-upload |
requires_selection | False |
Export
ID export
Choose fields and a file format for exporting records matching this dataview.
Models All models
| Field | Value |
|---|---|
icon | fa-solid fa-download |
shortcut | mod+4 |
requires_selection | False |
Display
ID display-options
Edit the view type and display settings for the active dataview preference.
Models All models
| Field | Value |
|---|---|
icon | fa fa-sliders |
shortcut | mod+5 |
requires_selection | False |
Saved Views
ID select-preference
Switch between saved views for this model.
Models All models
| Field | Value |
|---|---|
shortcut | mod+6 |
requires_selection | False |
Quick create
ID create-all-access-policy
Models bloomerp.policy
| Field | Value |
|---|---|
icon | fa fa-bolt |
requires_selection | False |
Create
ID create-workspace
Open the personal workspace creation form.
Models bloomerp.workspace
| Field | Value |
|---|---|
icon | fa fa-plus |
requires_selection | False |
create-voip-connection
ID create-voip-connection
Open the phone connection setup form.
Models bloomerp.voipconnection
| Field | Value |
|---|---|
requires_selection | False |
add_calendars
ID add_calendars
Choose additional inbox calendars to display.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
requires_selection | False |
Booking links
ID bookings
Manage booking links for the current inbox.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
icon | fa-regular fa-calendar-check |
requires_selection | False |
Back to inbox
ID back_to_inbox
Return from an inbox calendar to the inbox page.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
icon | fa fa-inbox |
requires_selection | False |
Filter
ID calendar-filter
Edit the conditions used to select records in the dataview.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
icon | fa fa-filter |
shortcut | mod+1 |
requires_selection | False |
All matching records
ID calendar-bulk-all-matching
Open bulk operations for every record matching the active search and filters.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
icon | fa fa-filter |
requires_selection | False |
Selected records
ID calendar-bulk-selected-records
Open bulk operations for the records selected in this dataview.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
icon | fa fa-list-check |
requires_selection | True |
Import
ID calendar-import
Open the bulk import page for this dataview's model.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
icon | fa-solid fa-upload |
requires_selection | False |
Export
ID calendar-export
Choose fields and a file format for exporting records matching this dataview.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
icon | fa-solid fa-download |
shortcut | mod+4 |
requires_selection | False |
Display
ID calendar-display-options
Edit the view type and display settings for the active dataview preference.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
icon | fa fa-sliders |
shortcut | mod+5 |
requires_selection | False |
Saved Views
ID calendar-select-preference
Switch between saved views for this model.
Models bloomerp.calendarevent
| Field | Value |
|---|---|
shortcut | mod+6 |
requires_selection | False |
Export YAML
ID export-tutorial-yaml
Download the selected tutorial as a YAML file in debug mode.
Models bloomerp.tutorial
| Field | Value |
|---|---|
method | GET |
icon | fa-solid fa-file-arrow-down |
requires_selection | False |
