BloomERP

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.

SettingTypeDefaultDescription
idstrRequiredStable ID used in action configuration.Minimum length: 1
documentationstr''Markdown and tagged examples included in the generated developer reference.
modelsModelSelector'__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.
methodstuple[Literal['GET', 'POST'], ...]('GET', 'POST')Allowed HTTP methods. The first is used by the action button.Minimum length: 1
methodOptional[Literal['GET', 'POST']]NoneLegacy single-method override for existing action definitions.
descriptionstr''The description of the action.
labelstr | NoneNoneOptional label for the action.
iconstr | NoneNoneOptional Font Awesome icon for the action.
shortcutstr | NoneNoneOptional keyboard shortcut, such as 'alt+arrowright' (Alt + Right Arrow), or a sequence like 'k then p'.
get_button_attrsCallable[[DataviewActionContext], dict[str, Any]]BaseActionDefinition.<lambda>Return additional HTML attributes for the default action button.
get_query_paramsCallable[[DataviewActionContext], ActionQueryParams] | NoneNoneReturn 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_visibleCallable[[DataviewActionContext], bool]BaseActionDefinition.<lambda>Determine whether to show the action in the current context.
executeCallable[[DataviewActionContext], HttpResponse | StreamingHttpResponse | None] | NoneNoneHandler for an action request. HTML-only controls can omit it.
success_messagestr | NoneNoneMessage shown when the handler returns no response.
refresh_on_successOptional[Literal['item', 'dataview']]NoneRefresh the originating record or dataview when the handler returns no response.
renderCallable[[DataviewActionContext, Mapping[str, Any]], str] | NoneNoneReturn an HTML fragment using the action context and surrounding template context. The template context includes the current definition under 'action'.
requires_selectionboolFalseShow 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.

python
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.

python
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

FieldValue
iconfa fa-filter
shortcutmod+1
requires_selectionFalse

Add

ID add

Open a form to create a record in this dataview's model.

Models All models

FieldValue
iconfa fa-plus
shortcutmod+2
requires_selectionFalse

All matching records

ID bulk-all-matching

Open bulk operations for every record matching the active search and filters.

Models All models

FieldValue
iconfa fa-filter
requires_selectionFalse

Selected records

ID bulk-selected-records

Open bulk operations for the records selected in this dataview.

Models All models

FieldValue
iconfa fa-list-check
requires_selectionTrue

Import

ID import

Open the bulk import page for this dataview's model.

Models All models

FieldValue
iconfa-solid fa-upload
requires_selectionFalse

Export

ID export

Choose fields and a file format for exporting records matching this dataview.

Models All models

FieldValue
iconfa-solid fa-download
shortcutmod+4
requires_selectionFalse

Display

ID display-options

Edit the view type and display settings for the active dataview preference.

Models All models

FieldValue
iconfa fa-sliders
shortcutmod+5
requires_selectionFalse

Saved Views

ID select-preference

Switch between saved views for this model.

Models All models

FieldValue
shortcutmod+6
requires_selectionFalse

Quick create

ID create-all-access-policy

Models bloomerp.policy

FieldValue
iconfa fa-bolt
requires_selectionFalse

Create

ID create-workspace

Open the personal workspace creation form.

Models bloomerp.workspace

FieldValue
iconfa fa-plus
requires_selectionFalse

create-voip-connection

ID create-voip-connection

Open the phone connection setup form.

Models bloomerp.voipconnection

FieldValue
requires_selectionFalse

add_calendars

ID add_calendars

Choose additional inbox calendars to display.

Models bloomerp.calendarevent

FieldValue
requires_selectionFalse

ID bookings

Manage booking links for the current inbox.

Models bloomerp.calendarevent

FieldValue
iconfa-regular fa-calendar-check
requires_selectionFalse

Back to inbox

ID back_to_inbox

Return from an inbox calendar to the inbox page.

Models bloomerp.calendarevent

FieldValue
iconfa fa-inbox
requires_selectionFalse

Filter

ID calendar-filter

Edit the conditions used to select records in the dataview.

Models bloomerp.calendarevent

FieldValue
iconfa fa-filter
shortcutmod+1
requires_selectionFalse

All matching records

ID calendar-bulk-all-matching

Open bulk operations for every record matching the active search and filters.

Models bloomerp.calendarevent

FieldValue
iconfa fa-filter
requires_selectionFalse

Selected records

ID calendar-bulk-selected-records

Open bulk operations for the records selected in this dataview.

Models bloomerp.calendarevent

FieldValue
iconfa fa-list-check
requires_selectionTrue

Import

ID calendar-import

Open the bulk import page for this dataview's model.

Models bloomerp.calendarevent

FieldValue
iconfa-solid fa-upload
requires_selectionFalse

Export

ID calendar-export

Choose fields and a file format for exporting records matching this dataview.

Models bloomerp.calendarevent

FieldValue
iconfa-solid fa-download
shortcutmod+4
requires_selectionFalse

Display

ID calendar-display-options

Edit the view type and display settings for the active dataview preference.

Models bloomerp.calendarevent

FieldValue
iconfa fa-sliders
shortcutmod+5
requires_selectionFalse

Saved Views

ID calendar-select-preference

Switch between saved views for this model.

Models bloomerp.calendarevent

FieldValue
shortcutmod+6
requires_selectionFalse

Export YAML

ID export-tutorial-yaml

Download the selected tutorial as a YAML file in debug mode.

Models bloomerp.tutorial

FieldValue
methodGET
iconfa-solid fa-file-arrow-down
requires_selectionFalse