Print Dropdown on Detail Views
Developer guide for the Enezaframework reporting engine. Part of the Add Report series.
Table of Contents
- Overview
- Setting print_actions
- Print vs. Actions Dropdown
- Dropdown Flow
- Template (navactions.html)
- ActionMixin.get_print_action_config()
- BaseDetailView Change
- Related Guides
Overview
Any detail view that inherits from BaseDetailView (or a subclass) can expose document
reports through a Print dropdown. Add a print_actions list and the framework renders
a printer-icon dropdown that fetches the report via HTMX with no confirmation step.
Setting print_actions
from enezaframework.views import BaseSourceDocumentDetailView
from enezaframework.utils import auto_url_register
from myapp.models import Invoice
@auto_url_register
class InvoiceDetailView(BaseSourceDocumentDetailView):
model = Invoice
print_actions = [
{
"name": "Invoice Report", # display name in the dropdown
"icon": "printer", # icon filename under the static icons/ folder, without extension
"url": "invoice_report", # URL name — matches report_name + '_report'
},
]
Each entry has three keys:
| Key | Type | Required | Description |
|---|---|---|---|
name |
str |
Yes | Display name in the Print dropdown. |
icon |
str |
Yes | Icon filename (without extension) resolved by load_icon, which looks under the static icons/ folder as icons/{name}.svg. |
url |
str |
Yes | URL name — matches report_name + _report. |
Print vs. Actions Dropdown
| Aspect | Print (print_actions) |
Actions (action_list) |
|---|---|---|
| HTTP method | hx-get (no confirmation) |
hx-post + confirmation |
| URL suffix | Direct — no suffix appended | _action appended automatically |
| Icon | Printer icon | Share icon (branching) |
| Position | After Save/Delete, before Workflow | After Workflow |
| Purpose | Report/print rendering | Operational actions (Post, Approve, etc.) |
Dropdown Flow
flowchart LR
DETAIL["Detail view<br/>model instance"] --> CFG["get_print_action_config()<br/>dicts → template format"]
CFG --> NAV["navactions.html<br/>Print dropdown"]
NAV -->|"hx-get"| URL["{report_name}_report/<str:pk>/"]
URL --> REPORT["DocumentReportPageView"]
REPORT -->|"hx-swap innerHTML"| CONTAINER["#detail-container"]Template (navactions.html)
The Print dropdown is rendered at
enezaframework/templates/core/partials/navactions.html. It uses:
- Alpine.js
x-data="dropdown"for toggle behavior. - HTMX
hx-gettargeting#detail-containerwithhx-swap="innerHTML". - URL construction:
{% url current_app|add:':'|add:action.url object.id %}. - Conditional display: hidden when
print_actionsis empty or falsy.
ActionMixin.get_print_action_config()
Defined in enezaframework/views/mixins.py. Converts the raw print_actions dict list
into a template-safe format with SVG icons:
def get_print_action_config(self, print_actions):
print_action_config = []
for action in print_actions:
action_dict = {
"name": action.get("name", None),
"icon": load_icon(action.get("icon", "printer")),
"url": action.get("url", ""),
}
print_action_config.append(action_dict)
return print_action_config
Unlike get_action_name_config(), this method does not append _action to the URL —
the URL name in print_actions is used verbatim.
BaseDetailView Change
print_actions = [] is defined on BaseDetailView (enezaframework/views/base.py) and
exposed in the context, giving all detail view subclasses Print dropdown capability with
no additional code. The dropdown is hidden while the list is empty.