Account

Smarter API Account Manifest handler.

class smarter.apps.account.manifest.brokers.account.AccountSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

Account serializer for smarter api.

class smarter.apps.account.manifest.brokers.account.SAMAccountBroker(*args, **kwargs)[source]

Bases: AbstractBroker

Handles Smarter API Account Manifest operations, including loading, validating, and parsing YAML manifests, and mapping them to Django ORM and Pydantic models.

This broker transforms between Django ORM and Pydantic models, ensuring data consistency for serialization and API responses.

This broker is responsible for:
  • Loading and validating Smarter API Account manifests.

  • Initializing the corresponding Pydantic model from manifest data.

  • Creating, updating, deleting, and querying Django ORM models representing account manifests.

  • Transforming Django ORM models into Pydantic models for serialization and deserialization.

Parameters:
  • _manifest (Optional[SAMAccount]) – The current manifest instance (SAMAccount), if loaded.

  • _pydantic_model (Type[SAMAccount]) – The Pydantic model class used for manifests.

  • _account (Optional[Account]) – The Django ORM Account instance associated with the manifest.

Note

The manifest must be explicitly initialized with manifest data, typically using **data from the manifest loader.

Warning

If the manifest loader or manifest metadata is missing, or if the account is not set, the manifest will not be initialized and may return None or raise an exception.

Example usage:

broker = SAMAccountBroker()
manifest = broker.manifest
if manifest:
    print(manifest.apiVersion, manifest.kind)

See also

  • SAMAccount

  • Account

  • SAMAccountMetadata

  • SAMAccountSpec

Added in version 1.0.0: Initial implementation of the Smarter API Account Manifest Broker.

property ORMMetaModelClass: Type[Account]

Return the Django ORM meta model class for the broker.

Returns:

The Django ORM meta model class definition for the broker.

Return type:

Type[Account]

property ORMModelClass: Type[Account]

Get the Django ORM model class for the Smarter API Account.

Returns:

The Django ORM Account model class.

Return type:

Type[Account]

property SAMModelClass: Type[SAMAccount]

Return the Pydantic model class for the broker.

Returns:

The Pydantic model class definition for the broker.

Return type:

Type[SAMAccount]

property SerializerClass: Type[AccountSerializer]

Get the Django REST Framework serializer class for the Smarter API Account.

Returns:

The AccountSerializer class.

Return type:

Type[ModelSerializer]

__init__(*args, **kwargs)[source]
apply(request, *args, **kwargs)[source]

Applies the manifest by copying its data to the Django ORM Account model and saving the model to the database.

Note

tags are handled separately because they are of type TaggableManager and require a different method to set them.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • args – Additional positional arguments.

  • kwargs – Additional keyword arguments.

Returns:

A JSON response indicating the result of the apply operation.

Return type:

SmarterJournaledJsonResponse

Raises:
  • SAMBrokerErrorNotReady – If the broker’s account is not set.

  • SAMBrokerError – If an error occurs during the apply process.

Caution

Fields that are not editable (such as id, created_at, updated_at, and account_number) are removed from the data before saving.

Example usage:

response = broker.apply(request)
print(response.status_code, response.data)
property brokered_account: Account | None

In order to disambiguate between the AccountMixin.account.

(the authenticated account making the request) and the Account resource being brokered, we use the term “brokered_account”.

Get the Django ORM Account instance associated with this broker.

Returns:

The Account instance if set, otherwise None.

Return type:

Optional[Account]

cache_invalidations()[source]

Handle broker specific cache invalidation logic.

Invalidates the cache for the Account and UserProfile models.

Return type:

None

delete(request, *args, **kwargs)[source]

Attention

Delete functionality is not implemented for the Smarter API Account.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • args – Additional positional arguments.

  • kwargs – Additional keyword arguments.

Raises:

SAMBrokerErrorNotImplemented – Always raised to indicate that delete is not implemented.

Returns:

A JSON response indicating that delete is not implemented.

Return type:

SmarterJournaledJsonResponse

deploy(request, *args, **kwargs)[source]

Attention

Deploy functionality is not implemented for the Smarter API Account.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • args – Additional positional arguments.

  • kwargs – Additional keyword arguments.

Raises:

SAMBrokerErrorNotImplemented – Always raised to indicate that deploy is not implemented.

Returns:

A JSON response indicating that deploy is not implemented.

Return type:

SmarterJournaledJsonResponse

describe(request, *args, **kwargs)[source]

Describe the manifest for the Smarter API Account.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • args – Additional positional arguments.

  • kwargs – Additional keyword arguments.

Raises:

SAMBrokerErrorNotReady – Raised when no account is found.

Returns:

A JSON response with the manifest description.

Return type:

SmarterJournaledJsonResponse

django_orm_to_manifest_dict()[source]

Converts a Django ORM Account model instance into a Pydantic-compatible Smarter API Account manifest dictionary.

Returns:

Dictionary formatted for Pydantic model consumption, suitable for serialization and API responses.

Return type:

dict

Raises:
  • SAMBrokerErrorNotReady – If the broker’s account is not set.

  • SAMAccountBrokerError – If the account data is invalid or cannot be converted.

Note

The output uses camelCase keys for compatibility with Pydantic models and API consumers.

Example usage:

manifest_dict = broker.django_orm_to_manifest_dict()
print(manifest_dict["apiVersion"], manifest_dict["kind"])

See also

Changed in version 1.0.0: Method now ensures camelCase conversion and excludes the primary key field.

example_manifest(request, *args, **kwargs)[source]

Return an example manifest for the Smarter API Account.

Returns:

A JSON response containing an example Smarter API Account manifest.

Return type:

SmarterJournaledJsonResponse

See also

  • SAMAccount

  • SAMAccountMetadata

  • SAMAccountSpec

  • SAMKeys

  • SAMMetadataKeys

  • SAMAccountSpecKeys

property formatted_class_name: str

Returns a formatted class name string for use in logging, providing a more readable identifier for this broker class.

Returns:

The formatted class name, including the parent class and SAMAccountBroker().

Return type:

str

Example usage:

logger.info(broker.formatted_class_name)
get(request, *args, **kwargs)[source]

Get the manifest(s) for the Smarter API Account.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • args – Additional positional arguments.

  • kwargs – Additional keyword arguments.

Returns:

A JSON response containing the Smarter API Account manifest(s).

Return type:

SmarterJournaledJsonResponse

Raises:
  • SAMBrokerErrorNotReady – If the broker’s account is not set.

  • SAMAccountBrokerError – If there is an error retrieving or serializing the account data.

property kind: str

Get the manifest kind for the Smarter API Account.

Returns:

The manifest kind string for the Smarter API Account.

Return type:

str

logs(request, *args, **kwargs)[source]

Attention

Logs functionality is not implemented for the Smarter API Account.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • args – Additional positional arguments.

  • kwargs – Additional keyword arguments.

Returns:

A JSON response indicating that logs is not implemented.

Return type:

SmarterJournaledJsonResponse

property manifest: SAMAccount | None

Get the manifest for the Smarter API Account as a Pydantic model.

Returns:

A SAMAccount Pydantic model instance representing the Smarter API Account manifest, or None if not initialized.

Note

The top-level manifest model (SAMAccount) must be explicitly initialized with manifest data, typically using **data from the manifest loader.

Tip

Child models within the manifest are automatically cascade-initialized by Pydantic, passing **data to each child’s constructor.

Warning

If the manifest loader or manifest metadata is missing, or if the account is not set, the manifest will not be initialized and None may be returned or an exception raised.

Example usage:

# Access the manifest property
manifest = broker.manifest
if manifest:
    print(manifest.apiVersion, manifest.kind)
manifest_to_django_orm()[source]

Transform the Smarter API Account manifest into a Django ORM model.

Return type:

dict

property name: str | None

Get the name of the Smarter API Account.

Returns:

The name of the Smarter API Account, or None if not set.

Return type:

Optional[str]

property orm_instance: Account | None

Return the Django ORM model instance for the broker.

Returns:

The Django ORM model instance for the broker.

Return type:

Optional[TimestampedModel]

orm_meta_instance_setter()[source]

Override of parent method to initialize the Django ORM meta model.

instance for the broker.

Return type:

None

prompt(request, *args, **kwargs)[source]

Prompt functionality is not implemented for the Smarter API Account.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • args – Additional positional arguments.

  • kwargs – Additional keyword arguments.

Raises:

SAMBrokerErrorNotImplemented – Always raised to indicate that prompt is not implemented.

Returns:

A JSON response indicating that prompt is not implemented.

Return type:

SmarterJournaledJsonResponse

undeploy(request, *args, **kwargs)[source]

Attention

Undeploy functionality is not implemented for the Smarter API Account.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • args – Additional positional arguments.

  • kwargs – Additional keyword arguments.

Raises:

SAMBrokerErrorNotImplemented – Always raised to indicate that undeploy is not implemented.

Returns:

A JSON response indicating that undeploy is not implemented.

Return type:

SmarterJournaledJsonResponse

exception smarter.apps.account.manifest.brokers.account.SAMAccountBrokerError(message=None, thing=None, command=None, stack_trace=None)[source]

Bases: SAMBrokerError

Base exception for Smarter API Account Broker handling.

property get_formatted_err_message