Skip to content

angee.base.impl

Framework base for registry-resolved implementation classes.

An :class:~angee.base.fields.ImplClassField column selects one of these by key. Beyond the behaviour its domain needs, an impl carries shared metadata and defaults — the field values the owning row materialises when the impl is chosen. Defaults merge along the MRO, so refinements inherit their base's defaults and override only what differs. Abstract bases leave key blank and stay out of the registry; concrete leaves register a key and are pickable.

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 (base → derived; derived wins).

Dict-valued defaults (e.g. a config preset) 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.

label is each impl's name, not a domain trait: a refinement that omits it reads from its key, never the base's label. icon/category inherit normally.

choice

python
@classmethod
def choice(cls) -> dict[str, Any]

Return this impl's pickable choice metadata for forms (key/label/icon/category/defaults).

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 (provided = the explicitly passed field names) — the reliable "unset" signal, so a boolean default such as login_enabled=True lands when omitted yet an explicit False the caller passed is never overwritten. A string foreign-key default resolves against the related model's slug (a missing target leaves the FK unset); mutable defaults are deep-copied so rows never alias the class-level dict.

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.

impl_key_for

python
@classmethod
def impl_key_for(cls,
                 field_name: str,
                 value: Any,
                 *,
                 default: str | None = None) -> str

Return the canonical registry key for one ImplClassField value.

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