confirmation
django_spire.core.components.confirmation
__all__ = ['BaseConfirmationComponent', 'BaseModelActionConfirmationComponent', 'BaseModelDeleteConfirmationComponent', 'ConfirmationRefusedError', 'DeleteOptions', 'ModelDeleteConfirmationComponent', 'ModelSetDeletedConfirmationComponent', 'PageDeleteOptions']
module-attribute
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.
Source code in django_spire/core/components/confirmation/base_component.py
confirm
Source code in django_spire/core/components/confirmation/base_component.py
ConfirmationRefusedError
Bases: DjangoSpireError
The confirmed action was not performed; its message tells the user why.
BaseModelActionConfirmationComponent
Bases: BaseConfirmationComponent, ABC
A :class:BaseConfirmationComponent for one action on one model row.
Built with the row, as instance=, it works for any model. Confirming
performs the action with perform_action(), which a subclass writes,
and fires confirmed with the row's pk.
model_name
property
instance
get_permission_model
Return the row's model, whose permissions Glue.ModelAccessMixin reads.
perform_action
abstractmethod
BaseModelDeleteConfirmationComponent
Bases: BaseModelActionConfirmationComponent, ABC
A :class:BaseModelActionConfirmationComponent worded and guarded as a
delete: confirming needs DELETE access, and title, message and
confirm_label name the row and its model when left unset.
A subclass deletes the row in perform_action().
template = 'django_spire/component/confirmation/model_delete_confirmation.html'
class-attribute
instance-attribute
confirm_access = Glue.Access.DELETE
class-attribute
instance-attribute
ModelDeleteConfirmationComponent
Bases: BaseModelDeleteConfirmationComponent
Deletes the row from the database, with the model's delete().
ModelSetDeletedConfirmationComponent
Bases: BaseModelDeleteConfirmationComponent
Soft-deletes the row, with the set_deleted() of Spire's history mixin.
DeleteOptions
dataclass
A row is deleted through a confirmation component, shown in a modal.
component is the confirmation, which soft-deletes the row with
set_deleted() unless another is given. It fires confirmed with the
row's pk.
component = ModelSetDeletedConfirmationComponent
class-attribute
instance-attribute
__post_init__
Source code in django_spire/core/components/confirmation/options.py
PageDeleteOptions
dataclass
A row is deleted on a page of its own. url_name is the route that
takes the row's key as pk.
The link carries a return_url for the page to send the user to
afterwards: the route named by return_url_name, or when that is left
out, the address the list is shown at. A page that does not read
return_url goes wherever it always does.