Skip to content

angee.resources.entries

Value objects for declared addon resource files and parsed rows.

_ResourceAddon

python
class _ResourceAddon(Protocol)

Addon facts consumed by resource declarations.

name

python
@property
def name() -> str

Return the full dotted Django app name.

label

python
@property
def label() -> str

Return the short Django app label.

path

python
@property
def path() -> str

Return the filesystem path to the addon package root.

resolve_model

python
def resolve_model(label: str) -> type[models.Model]

Return the model class named by an app_label.ModelName label.

ResourceDeclaration

One normalized resource entry declaration.

AdoptDeclaration

Normalized resource adoption declaration.

EntryKey

Dependency graph key identifying one resource entry by addon and source.

RESERVED_ROW_KEYS

Row keys interpreted by the resource loader rather than model fields.

TEXT_FORMATS

Supported text resource formats keyed by file suffix.

STRUCTURED_FORMATS

Text formats that can carry _meta and rows envelopes.

resource_manifest_for

python
def resource_manifest_for(
        app_config: AppConfig) -> dict[str, tuple[dict[str, Any], ...]]

Return normalized resource declarations keyed by tier for one addon.

ResourceEntry

python
@dataclass(slots=True)
class ResourceEntry()

One local or remote resource file declared by an addon.

addon

Addon that owns this resource declaration.

tier

Normalized resource tier value.

source_key

Registered source key (path for a local file; url once integrate adds it).

source_value

The source's stored value — an addon-relative path, a URL, etc.

model

Optional fallback model label for every row in the file.

encoding

Text encoding used when reading the materialized file.

depends_on

Resource source keys that must load before this entry.

adopt

Unique field(s) used for adoption; True infers one unique field.

from_declaration

python
@classmethod
def from_declaration(cls, addon: _ResourceAddon, tier: str,
                     declaration: ResourceDeclaration) -> ResourceEntry

Return an entry from a resource declaration, resolving its source type.

source

python
@property
def source() -> str

Return this entry's stable source value (path, URL, …).

display

python
@property
def display() -> str

Return an owner-qualified name for diagnostics.

materialize

python
def materialize() -> Path

Return the local file path, materializing the source once.

read_resource_rows

python
def read_resource_rows() -> tuple[ResourceRow, ...]

Return parsed and normalized rows from this entry.

infer_model_label

python
def infer_model_label() -> str

Infer app.Model from a [NNN_]app.model.ext filename.

EntryGraph

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

Dependency graph for a selected set of resource entries.

entries

Entries selected for one resource operation.

from_entries

python
@classmethod
def from_entries(cls, entries: Iterable[ResourceEntry]) -> EntryGraph

Return a graph over entries in their selected order.

ordered

python
def ordered() -> tuple[ResourceEntry, ...]

Return entries in dependency order, preserving independent order.

ResourceRow

python
@dataclass(slots=True)
class ResourceRow()

One normalized resource row.

entry

Entry that contributed this row.

model_label

Django model label targeted by this row.

xref

Addon-local external row key.

values

Model field values to import.

from_record

python
@classmethod
def from_record(cls,
                entry: ResourceEntry,
                record: Mapping[str, Any],
                *,
                index: int,
                fallback_model: str | None = None) -> ResourceRow

Return a normalized row from parsed file data.

dataset_row

python
@property
def dataset_row() -> dict[str, Any]

Return the row as an import-export dataset mapping.

ResourceGroup

python
@dataclass(slots=True)
class ResourceGroup()

Rows from one entry that target one model.

entry

Resource entry that supplied the rows.

model

Django model imported by this group.

rows

Rows loaded into the target model.

to_dataset

python
def to_dataset() -> tablib.Dataset

Return this group as a tablib dataset.

ValidationResult

python
@dataclass(slots=True)
class ValidationResult()

Counts returned by resource validation.

checked_files

Number of resource files checked.

checked_rows

Number of resource rows checked.

LoadResult

python
@dataclass(slots=True)
class LoadResult()

Counts returned by a resource load.

created

Rows created during the load.

updated

Rows updated during the load.

skipped

Rows skipped because the ledger already matched.

with_result

python
def with_result(result: Result) -> LoadResult

Return this load count plus import-export's native result totals.

loaded

python
@property
def loaded() -> int

Return the number of created or updated rows.

Released under the AGPL-3.0 License.