Custom pages
Custom pages live on the AdminSite. They reuse the Chassis shell
(sidebar, navbar, brand, breadcrumbs) but are not ModelAdmins. Each class
must declare exactly one access contract.
| Class | Access | Groups |
|---|---|---|
PermissionAdminPage | PermissionOption with a view_* codename | may join navbar / dashboard groups |
PersonalAdminPage | authenticated staff | cannot join groups |
SuperuserAdminPage | active superuser | may join groups |
All of them subclass AdminPage. Site construction raises
ImproperlyConfigured if a class mixes two contracts, omits all three, or
puts a personal page in a group.
from django.http import HttpRequest, HttpResponse
from django.utils.translation import gettext_lazy as _
from django_chassis.options import AdminPageGroupOption, PermissionOption
from django_chassis.views import PermissionAdminPage
reports_group = AdminPageGroupOption(slug='reports', label=_('Reports'), icon_class='fa-solid fa-chart-line', order=10)
view_inventory = PermissionOption(
app_label='catalog', model='book', codename='view_inventory', name=_('Can view inventory')
)
class InventoryPage(PermissionAdminPage):
slug = 'inventory'
title = _('Inventory')
label = _('Inventory')
description = _('Stock overview')
icon_class = 'fa-solid fa-boxes-stacked'
permission = view_inventory
navbar_group = reports_group
dashboard_group = reports_group
def view(self, request: HttpRequest) -> HttpResponse:
return self.render(request, rows=[])
Register the class on the site:
class CustomAdminSite(ChassisAdminSiteMixin, AdminSite):
chassis_page_classes = (InventoryPage,)
AdminPageService mounts the routes. Put a PermissionAdminPage in
sidebar_items with SidebarPageItemOption(page_slug='inventory') if it
should appear in the sidebar. Personal and superuser pages cannot be
sidebar children.
Page anatomy
Default template: admin/chassis/page.html.
┌─ breadcrumbs ─────────────────────────────────────────────┐
│ Dashboard › Sidebar section › page label │
├─ toolbar (`page_actions`) ────────────────────────────────┤
│ optional page-level buttons (information pages) │
├─ title / description ─────────────────────────────────────┤
├─ `chassis_page_content` ──────────────────────────────────┤
│ whatever `view()` / `render()` puts in context │
└───────────────────────────────────────────────────────────┘
The shared page shell uses the full content width and renders form validation
errors through the common danger alert. Use chassis-page-actions for a
consistent right-aligned lower action panel and
admin/chassis/back_button.html for navigation back. The shared
form_rows.html template marks required fields and moves required confirmation
checkboxes after the other controls.
dispatch() checks has_view_permission. Failure raises
PermissionDenied (Chassis error page if
AdminErrorPageMiddleware is installed). Success calls view().
render(request, **context) merges:
admin_site.each_context(request)(brand, sidebar, navbar, footer)chassis_page— the page instancetitle/sidebar_section_labelfromAdminSidebarService- any extra kwargs you pass
AdminPage attributes
| Attribute | Type | Default | Purpose |
|---|---|---|---|
slug | str | required | URL segment and sidebar reference |
title | localized string | required | Heading |
label | localized string | required | Navigation label |
description | localized string | '' | Optional lead |
icon_class | Font Awesome class | 'fa-solid fa-table-list' | Sidebar / groups |
order | int | 0 | Sort key among pages |
template_name | str | 'admin/chassis/page.html' | Override per page |
filters_fieldset_title | localized string | _('Фильтры') | If the page renders filters |
chassis_settings | Settings | Settings() | Same collapsed / add flags as ModelAdmin |
navbar_group | AdminPageGroupOption or None | None | Navbar dropdown |
dashboard_group | AdminPageGroupOption or None | None | Dashboard actions section |
route_prefix | str | 'pages' | First URL segment |
URL: {admin}/{route_prefix}/{slug}/. URL name: chassis_page_{slug}
(namespaced with the AdminSite name).
Implement view(self, request) (not get() / post() on the base —
dispatch always calls view). Branch on request.method inside
view if you need POST.
Access contracts
PermissionAdminPage
permission must be a PermissionOption whose codename starts with
view_. The site registers it automatically. The check uses
AdminPermissionService / has_request_user_permission (group-only by
default).
PersonalAdminPage
Any authenticated staff user. Must not set navbar_group or
dashboard_group. Use this for "my profile", "my tokens", and similar
per-user screens.
SuperuserAdminPage
request.user.is_active and is_superuser.
Object pages
AdminObjectPage[T] extends a custom page with a list URL, an
object card, and @object_action methods. The object does not
have to be a Django model: you resolve it yourself.
Extra routes:
| Route | Name |
|---|---|
{prefix}/{slug}/ | chassis_page_{slug} — list (view) |
{prefix}/{slug}/{object_id}/ | chassis_page_{slug}_object |
{prefix}/{slug}/{object_id}/actions/{action_name}/ | chassis_page_{slug}_object_action |
You implement:
| Method | Role |
|---|---|
view(request) | list page |
get_object(request, object_id) -> T | None | None → HTTP 404 |
get_object_context_data(request, object_id, obj) | extra card context |
object_actions | list of @object_action method names |
Card template: admin/chassis/object_page.html (object_template_name).
The card toolbar lists allowed object actions. Permission and
condition / condition_method are re-checked on the action URL.
If the object disappeared, the action redirects to the list with an error message. Unknown or forbidden actions redirect back to the card.
Information pages
AdminInformationPage is a structured report (sections, alerts, header
actions, timelines). See Information pages.
See also
Wizard pages
Added in 1.0.22Combine WizardAdminPage with one access contract. The
two-step wizard recipe shows a form, review page and server-side transition checks.
Operations
Added in 1.0.24Register the Operations page and its primary navbar button together. Keep the
existing Observability page and detail modal to retain their URL names and add
the audit, attention, HTTP events and import/export tabs to Operations. Remove
OBSERVABILITY_SIDEBAR_LINK from the site's sidebar when adopting the navbar
button.
from django.contrib.admin import AdminSite
from django_chassis.mixins import ChassisAdminSiteMixin
from django_chassis.navbar import OperationsAdminNavbarButton
from django_chassis.views import ObservabilityAdminPage, ObservationDetailModal, OperationsAdminPage
class ProjectAdminSite(ChassisAdminSiteMixin, AdminSite):
navbar_button_classes = (OperationsAdminNavbarButton,)
chassis_page_classes = (OperationsAdminPage, ObservabilityAdminPage)
chassis_modal_classes = (ObservationDetailModal,)
The default tab is Summary. The Nodes, Stuck tasks and Caches tabs show the relevant registered sources. A user can open Operations when they can access at least one source or a configured summary. Direct links and tabs use the same permissions. The runtime resources section requires a superuser. When an observation tab is available, its existing period, filters and modal URLs continue to work.
Subclass OperationsAdminPage to connect project data. The provider protocols
are exported from django_chassis.providers and their results from
django_chassis.dto. Set the providers as class attributes.
summary_provider(request=...)returnsOperationsSummaryDTOfrom stored observations and cached snapshots. Its optionalRabbitMQManagementSnapshotDTOis for counts collected from an explicitly configured read-only RabbitMQ Management API with a bounded timeout. Userabbitmq_statefor the outcome of the separate AMQP probe. Collect both outside the GET request.nodes_provider(request=..., limit=...)returns a sequence ofOperationsNodeDTOwith display names, roles, state and last observation time.summary_permissionandnodes_permissionaccept Django permission names. Their defaultNonerequires a superuser.- The optional standard Celery list reads
django_celery_results.TaskResultwithdjango_celery_results.view_taskresult. It showsSTARTEDandRETRYrecords older thancelery_task_soft_time_limitin seconds, orCELERY_TASK_SOFT_TIME_LIMITif the page option is unset. It usesdate_createdwhendate_startedis unavailable. - Register durable tasks in
stuck_task_sourceswithOperationsStuckTaskSourceOption(title=..., provider=..., permission=...). The provider receivesrequest,untilandlimitas keyword arguments and returns a sequence ofOperationsTaskDTO. Each source returns up to 100 rows. Omit its permission to require a superuser.
Providers return None for an unavailable source. An empty sequence means the
source is available and has no rows. Use safe display names and metadata for
nodes, tasks and cache keys.
Cache aliases and keys
Declare cache_aliases as a sequence of OperationsCacheAliasOption values.
Each registration identifies a Django alias and its expected backend class
path, a display label and an ordered sequence of OperationsCacheKeyOption
values. A key has a stable slug, exact logical key and display label.
The page inspects at most 100 registered keys. Set cache_view_permission to
grant access to operators. The default requires a superuser.
The built-in LocMemCache reader supports presence checks. Other backends or
TTL measurements use a registered inspector(alias=..., key=..., include_value=...)
that returns OperationsCacheKeySnapshotDTO or None when unavailable.
Use backend-native metadata operations and bounded reads in the adapter.
Set show_value=True only for a deliberately visible text value. The page caps
visible text at 512 characters. Mark an alias or key is_sensitive=True to
restrict it to metadata. The configured Django cache session alias always
uses this restriction when sessions are cached.
To allow a rebuild, set a key's rebuild(alias=..., key=...) callback to
recreate that exact key from its database source and return whether it
succeeded. The operator needs cache_change_permission in addition to cache
view access. The default change permission requires a superuser. Chassis uses
a CSRF-protected confirmation and records the outcome in the Django Admin log.
Sensitive keys and session aliases are read-only.
Observability
Added in 1.0.23Register the page and its detail dialog on a Chassis AdminSite with
AdminAuditLog registered. The built-in users module registers that model.
Install AdminAuditMiddleware to collect new events
under the site's admin path.
from django.contrib.admin import AdminSite
from django_chassis.mixins import ChassisAdminSiteMixin
from django_chassis.sidebar import OBSERVABILITY_SIDEBAR_LINK
from django_chassis.views import ObservabilityAdminPage, ObservationDetailModal
class CustomAdminSite(ChassisAdminSiteMixin, AdminSite):
chassis_page_classes = (ObservabilityAdminPage,)
chassis_modal_classes = (ObservationDetailModal,)
sidebar_items = (OBSERVABILITY_SIDEBAR_LINK,)
See the Observability walkthrough for the rendered overview.
The page and its sidebar link use django_chassis.view_adminauditlog.
The audit tabs use the registered ModelAdmin's queryset. They show a summary,
recent unsuccessful requests and recent HTTP events. Transfer history and
transfer details require superuser access. The page URL name is
chassis_page_observability in the site's namespace.
Set CHASSIS_OBSERVATION_PERIOD_HOURS to an integer from 1 to 720. The default is
24 hours. To add a database check tab, subclass ObservabilityAdminPage and
set database_history_provider to a function or bound method that accepts
keyword arguments request, since and until and returns
django_chassis.dto.AvailabilityHistoryDTO. Register the subclass in
chassis_page_classes. The provider checks access to its measurements and
returns the samples it has for that period. Pass timezone-aware interval
boundaries, with samples in chronological order and without overlap. Use
state='unknown' for intervals without measurements.