Skip to content

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

python
@dataclass(frozen=True, slots=True)
class ImplChoice()

Pickable implementation metadata shared by GraphQL and form defaults.

ImplBase

python
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

python
@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

python
@classmethod
def display_label(cls) -> str

Return this impl's own label, falling back to a title-cased key.

choice

python
@classmethod
def choice(cls) -> ImplChoice

Return this impl's pickable choice metadata for forms.

materialize

python
@classmethod
def materialize(cls,
                instance: models.Model,
                *,
                provided: frozenset[str] = frozenset()) -> None

Seed 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

python
def impl_registry(registry_setting: str) -> dict[str, str]

Return the configured key -> dotted path mapping for registry_setting.

resolve_impl_class

python
def resolve_impl_class(registry_setting: str, key: str,
                       base_class: type) -> type

Return 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

python
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__

python
def __init__(*,
             base_class: type | None = None,
             registry_setting: str = "",
             **kwargs: Any) -> None

Bind the implementation base and build the enum from the registry keys.

deconstruct

python
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

python
def check(**kwargs: Any) -> list[checks.CheckMessage]

Validate the declaration and every configured impl path.

resolve_class

python
def resolve_class(key: Any) -> type

Return the impl class the configured mapping binds to key.

registered_keys

python
def registered_keys() -> tuple[str, ...]

Return this field's configured implementation keys in deterministic order.

resolve_for

python
def resolve_for(instance: models.Model) -> type

Return the impl class selected by this field on instance.

key_for

python
def key_for(value: Any) -> str

Return the canonical registry key for a stored/input enum-ish value.

impl_choices

python
def impl_choices() -> list[ImplChoice]

Return pickable choices for the registry in deterministic key order.

ImplDefaultsMixin

python
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

python
class Meta()

Abstract: contributes the create-time default seeding only.

__init__

python
def __init__(*args: Any, **kwargs: Any) -> None

Record the caller-supplied field names so create-time seeding skips them.

save

python
def save(*args: Any, **kwargs: Any) -> None

Seed impl defaults for unsupplied fields on first insert, then persist.

set_impl_key

python
def set_impl_key(field_name: str,
                 value: Any,
                 *,
                 default: str | None = None) -> bool

Assign an impl key and return whether the stored key changed.

materialize_impl_defaults

python
def materialize_impl_defaults(
    field_name: str, *, provided: frozenset[str] = frozenset()) -> None

Apply the selected impl's defaults for one impl field.

Released under the AGPL-3.0 License.