angee.base.impl
Registry-backed implementation selection for Angee models and settings.
This module is the single owner of the impl mechanism: the model field that stores a selected key, the metadata base classes impls subclass, and the settings-backed registry resolver shared by row-owned and row-less selectors.
ImplChoice
@dataclass(frozen=True, slots=True)
class ImplChoice()Pickable implementation metadata shared by GraphQL and form defaults.
ImplBase
class ImplBase()Base for an implementation selectable by an ImplClassField key.
Subclasses declare class-level key/label/icon/category and a defaults mapping of model-field values to seed. Behaviour lives on the domain subclass (e.g. IntegrationImpl, OAuthProviderType).
effective_defaults
@classmethod
def effective_defaults(cls) -> dict[str, Any]Return this impl's defaults merged along the MRO, with derived values winning.
Dict-valued defaults merge one level deep, so a refinement adds keys to its base's dict default instead of replacing it; scalar values are overridden outright.
display_label
@classmethod
def display_label(cls) -> strReturn this impl's own label, falling back to a title-cased key.
choice
@classmethod
def choice(cls) -> ImplChoiceReturn this impl's pickable choice metadata for forms.
materialize
@classmethod
def materialize(cls,
instance: models.Model,
*,
provided: frozenset[str] = frozenset()) -> NoneSeed instance's fields from this impl's effective defaults on create.
Seeds only fields the caller did not supply. A string foreign-key default resolves against the related model's slug; mutable defaults are deep-copied so rows never alias the class-level dict.
impl_registry
def impl_registry(registry_setting: str) -> dict[str, str]Return the configured key -> dotted path mapping for registry_setting.
resolve_impl_class
def resolve_impl_class(registry_setting: str, key: str,
base_class: type) -> typeReturn the impl class registry_setting binds to key.
The dotted path comes from composed, trusted settings and is checked against base_class before returning.
ImplClassField
class ImplClassField(TextChoicesField)A column naming a non-model implementation class by a short key.
registry_setting names the Django setting that maps keys to dotted import paths. Addons contribute impls into that setting through autoconfig, making the key set closed at composition time. The field renders as a TextChoices enum and resolves only configured, trusted paths.
__init__
def __init__(*,
base_class: type | None = None,
registry_setting: str = "",
**kwargs: Any) -> NoneBind the implementation base and build the enum from the registry keys.
deconstruct
def deconstruct() -> tuple[str | None, str, list[Any], dict[str, Any]]Emit a plain varchar column and rebuild the enum from settings on reconstruct.
check
def check(**kwargs: Any) -> list[checks.CheckMessage]Validate the declaration and every configured impl path.
resolve_class
def resolve_class(key: Any) -> typeReturn the impl class the configured mapping binds to key.
registered_keys
def registered_keys() -> tuple[str, ...]Return this field's configured implementation keys in deterministic order.
resolve_for
def resolve_for(instance: models.Model) -> typeReturn the impl class selected by this field on instance.
key_for
def key_for(value: Any) -> strReturn the canonical registry key for a stored/input enum-ish value.
impl_choices
def impl_choices() -> list[ImplChoice]Return pickable choices for the registry in deterministic key order.
ImplDefaultsMixin
class ImplDefaultsMixin(models.Model)Materialise impl defaults on create for every ImplClassField on the model.
The backend safety net behind the form-level prefill: a row created without a form (API, resource seed) still gets the chosen impl's defaults — for the fields the caller did not supply. Form-created rows pass their (possibly edited) values, so the impl never overrides them, even when a value equals the model default.
Meta
class Meta()Abstract: contributes the create-time default seeding only.
__init__
def __init__(*args: Any, **kwargs: Any) -> NoneRecord the caller-supplied field names so create-time seeding skips them.
save
def save(*args: Any, **kwargs: Any) -> NoneSeed impl defaults for unsupplied fields on first insert, then persist.
set_impl_key
def set_impl_key(field_name: str,
value: Any,
*,
default: str | None = None) -> boolAssign an impl key and return whether the stored key changed.
materialize_impl_defaults
def materialize_impl_defaults(
field_name: str, *, provided: frozenset[str] = frozenset()) -> NoneApply the selected impl's defaults for one impl field.