SAM AbstractController Class

class smarter.lib.manifest.controller.AbstractController(user_profile, *args, **kwargs)[source]

Bases: ABC, AccountMixin

Abstract base class for mapping a manifest model’s metadata.kindClass to the correct Python object instance.

This controller is designed to facilitate the instantiation and management of objects based on manifest metadata, ensuring that the correct subclass is used for each manifest type. It also provides account and user context through the AccountMixin.

Parameters:
  • user_profile (UserProfile) – The user profile that owns the controlled resource. Its account and user are the controller’s account and user.

  • args (Any) – Passed on to AccountMixin.

  • kwargs (Any) – Passed on to AccountMixin, e.g. request.

Usage Example:

user_profile = UserProfile.get_cached_object(user=user)
controller = MyControllerSubclass(user_profile, request=request)

# Access manifest, map, and obj properties
manifest = controller.manifest
mapping = controller.map
obj_instance = controller.obj

Note

This class is abstract and must be subclassed with concrete implementations of the manifest, map, and obj properties.

Warning

A subclass that does not implement all of the abstract properties cannot be instantiated.

__init__(user_profile, *args, **kwargs)[source]

Initialize the account context from the user profile, with one AccountMixin initialization.

Parameters:
abstract property manifest: AbstractSAMBase | None

The Pydantic manifest of the controlled resource, or None if there is none yet; subclasses implement it.

abstract property map: Mapping[str, Any]

The mapping from manifest kinds to the classes that handle them; subclasses implement it.

abstract property obj: Any

The object that handles the manifest’s kind, from map; subclasses implement it.