base_component
django_spire.core.components.confirmation.base_component
BaseConfirmationComponent
Bases: Component, ABC
Asks the user to confirm one action.
Subclasses perform the action in on_confirm(). The prompt is worded
when the component is built, with title, message and
confirm_label; one left unset keeps the template's own wording::
ArchiveConfirmationComponent(title='Archive this report?', confirm_label='Archive')
A subclass that needs markup, such as an icon, extends the template's
confirmation_title, confirmation_message and
confirmation_button blocks. confirmation_button holds the whole
confirm button.
The component does not know what it is shown in, so it closes nothing.
Whoever shows it listens for confirmed, which carries what
on_confirm() returned, and for cancelled, and puts it away.
Cancelling does nothing on the server, so the template raises
cancelled in the browser.
What the user sees once the action is done, such as a toast, is the
template's: its on_confirmed block runs in the browser after a
successful confirm(), with what on_confirm() returned as
result, as a form's glue_form_on_saved block does after a save.
An action that cannot be performed, because its row changed while the
prompt was open say, raises ConfirmationRefusedError: confirmed is
not fired, and the prompt stays open and shows the error's message.
confirm_access is the access the user needs in order to confirm.
template = 'django_spire/component/confirmation/confirmation.html'
class-attribute
instance-attribute
confirm_access = Glue.Access.VIEW
class-attribute
title = Glue.ComponentParameter(None)
class-attribute
instance-attribute
message = Glue.ComponentParameter(None)
class-attribute
instance-attribute
confirm_label = Glue.ComponentParameter(None)
class-attribute
instance-attribute
cancelled = Glue.event()
class-attribute
instance-attribute
confirmed = Glue.event()
class-attribute
instance-attribute
on_confirm
abstractmethod
Perform the confirmed action and return the detail of confirmed, or
raise ConfirmationRefusedError to leave the prompt open with its message.