Skip to content

action_component

django_spire.core.components.confirmation.model.action_component

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}