Skip to content

model

django_spire.core.components.confirmation.model

__all__ = ['BaseModelActionConfirmationComponent', 'BaseModelDeleteConfirmationComponent', 'ModelDeleteConfirmationComponent', 'ModelSetDeletedConfirmationComponent'] module-attribute

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

Source code in django_spire/core/components/confirmation/model/action_component.py
@Glue.ComponentParameter
def instance(self, model: type[Model], pk: int) -> Model:
    return model._default_manager.get(pk=pk)

get_permission_model

Return the row's model, whose permissions Glue.ModelAccessMixin reads.

Source code in django_spire/core/components/confirmation/model/action_component.py
def get_permission_model(self) -> type[Model]:
    """Return the row's model, whose permissions ``Glue.ModelAccessMixin`` reads."""
    return self.instance._meta.model

perform_action abstractmethod

Perform the confirmed action on self.instance.

Source code in django_spire/core/components/confirmation/model/action_component.py
@abstractmethod
def perform_action(self) -> None:
    """Perform the confirmed action on ``self.instance``."""

on_confirm

Source code in django_spire/core/components/confirmation/model/action_component.py
def on_confirm(self) -> dict[str, Any]:
    pk = self.instance.pk

    self.perform_action()

    return {'pk': pk}

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().

perform_action

Source code in django_spire/core/components/confirmation/model/delete_component.py
def perform_action(self) -> None:
    self.instance.delete()

ModelSetDeletedConfirmationComponent

Bases: BaseModelDeleteConfirmationComponent

Soft-deletes the row, with the set_deleted() of Spire's history mixin.

perform_action

Source code in django_spire/core/components/confirmation/model/delete_component.py
def perform_action(self) -> None:
    self.instance.set_deleted()