Skip to content

Hooks

CommandHook

Base class for command execution hooks.

Subclass and implement setup(), pre_save(), and/or post_save().

pre_save

pre_save(
    command_name: str,
    kwargs: dict,
    execution: CommandExecution,
    ctx: HookContext,
) -> None

Called after command execution but before the DB save.

Source code in src/django_admin_runner/hooks.py
def pre_save(
    self,
    command_name: str,
    kwargs: dict,
    execution: CommandExecution,
    ctx: HookContext,
) -> None:
    """Called after command execution but before the DB save."""
    ...

post_save

post_save(
    command_name: str,
    kwargs: dict,
    execution: CommandExecution,
    ctx: HookContext,
) -> None

Called after the DB save completes. Replaces the old teardown().

Source code in src/django_admin_runner/hooks.py
def post_save(
    self,
    command_name: str,
    kwargs: dict,
    execution: CommandExecution,
    ctx: HookContext,
) -> None:
    """Called after the DB save completes.  Replaces the old ``teardown()``."""
    ...

teardown

teardown(
    command_name: str,
    kwargs: dict,
    execution: CommandExecution,
    ctx: HookContext,
) -> None

Deprecated: override :meth:post_save instead.

Source code in src/django_admin_runner/hooks.py
def teardown(
    self,
    command_name: str,
    kwargs: dict,
    execution: CommandExecution,
    ctx: HookContext,
) -> None:
    """Deprecated: override :meth:`post_save` instead."""
    self.post_save(command_name, kwargs, execution, ctx)

HookContext

HookContext()

Dict-like state bag scoped to a single command execution.

Lets hooks share data between setup() and teardown() without coupling hooks to each other. A fresh instance is created per execution.

Source code in src/django_admin_runner/hooks.py
def __init__(self) -> None:
    self._data: dict[str, object] = {}

TempFileHook

Bases: CommandHook

Creates a unique upload directory under ADMIN_RUNNER_UPLOAD_PATH in setup() and removes it in post_save().

Only active when ADMIN_RUNNER_UPLOAD_PATH is configured.