This repository has been archived on 2026-04-16. You can view files and clone it, but cannot push or open issues or pull requests.
substrate-sdk-python/substrate_sdk/django/signals.py
Tyler King 89a054d656 initial: substrate-sdk-python v0.1.0
Python SDK for shellbound Django applications.
Provides ShellApp, ShardContext, ShellboundMiddleware.
Emits Chronicle events to stdout in dev mode.

Includes fix for IndexError in apps.py when
DJANGO_SETTINGS_MODULE has no dots (e.g.
instance_settings). Shard name now falls back
safely without eager default argument parsing.

Implements SHELLBOUND-APP-0001 §4 (dev mode).
Wired into entropyopposition as of 2026-03-18.
2026-03-18 13:53:58 -04:00

25 lines
731 B
Python

"""Connect Django signals to Chronicle events."""
import logging
logger = logging.getLogger(__name__)
def connect_signals(emitter):
"""Connect Django model signals to Chronicle. No-op if emitter is None."""
if not emitter:
return
from django.db.models.signals import post_save
def on_post_save(sender, instance, created, **kwargs):
try:
emitter.signal(
signal_name="post_save_create" if created else "post_save_update",
model=sender.__name__,
instance_id=str(getattr(instance, "pk", "")),
)
except Exception as e:
logger.debug("Signal Chronicle non-fatal: %s", e)
post_save.connect(on_post_save)