flexmeasures.data.schemas.account
Classes
- class flexmeasures.data.schemas.account.AccountCreateSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
Schema for creating an account via API.
- set_consultancy_account_default(data, **kwargs)
Set consultancy_account_id to current user’s account for consultants/account-admins.
This runs after validation, so we know the user has the required roles. Only applies when consultancy_account_id is None or missing.
- validate_consultancy_account_id(value, **kwargs)
Validate consultancy_account_id field for account creation.
Uses shared validation logic. For POST requests, None is allowed and will be defaulted in @post_load.
- class flexmeasures.data.schemas.account.AccountIdField(*args, **kwargs)
Field that deserializes to an Account and serializes back to an integer.
- class flexmeasures.data.schemas.account.AccountIdOrListField(*, load_default: ~typing.Any = <marshmallow.missing>, dump_default: ~typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: ~typing.Callable[[~typing.Any], ~typing.Any] | ~typing.Iterable[~typing.Callable[[~typing.Any], ~typing.Any]] | None = None, pre_load: ~typing.Callable[[~typing.Any], ~typing.Any] | ~typing.Iterable[~typing.Callable[[~typing.Any], ~typing.Any]] | None = None, post_load: ~typing.Callable[[~marshmallow.types.T], ~marshmallow.types.T] | ~typing.Iterable[~typing.Callable[[~marshmallow.types.T], ~marshmallow.types.T]] | None = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str | list | dict] | None = None, metadata: ~typing.Mapping[str, ~typing.Any] | None = None)
Field that accepts a single account ID or a non-empty list of account IDs.
Both
42and[42, 99]are accepted. Always deserializes to a list ofAccountinstances.The field is intentionally expressed as a union of
integerandarray[integer]rather than always requiring a list, so that future OpenAPI generation can emit aoneOfschema for it.- _deserialize(value: Any, attr, data, **kwargs) list[Account]
Deserialize value. Concrete
Fieldclasses should implement this method.- Parameters:
value – The value to be deserialized.
attr – The attribute/key in data to be deserialized.
data – The raw input data passed to the Schema.load <marshmallow.Schema.load>.
kwargs – Field-specific keyword arguments.
- Raises:
ValidationError – In case of formatting or validation failure.
- Returns:
The deserialized value.
Changed in version 3.0.0: Added
**kwargsto signature.
- _serialize(value: Any, attr, obj, **kwargs)
Serializes
valueto a basic Python datatype. Noop by default. ConcreteFieldclasses should implement this method.Example:
class TitleCase(Field): def _serialize(self, value, attr, obj, **kwargs): if not value: return "" return str(value).title()
- Parameters:
value – The value to be serialized.
attr – The attribute or key on the object to be serialized.
obj – The object the value was pulled from.
kwargs – Field-specific keyword arguments.
- Returns:
The serialized value
- class flexmeasures.data.schemas.account.AccountPatchSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
Schema for updating an account via API.
- transform_account_roles(data, **kwargs)
Transform account_roles from list of IDs to list of AccountRole objects.
Validates that: - account_roles is a list of integers - All role IDs exist in the database
- Raises:
FMValidationError: If validation fails
- validate_consultancy_account_id(value, **kwargs)
Validate consultancy_account_id field for account updates.
Uses shared validation logic. For PATCH requests, None clears the relationship.
- validate_plan_id(value, **kwargs)
Validate the plan an account is being put on.
Which plan an account is on decides what it may ask of the server, so only admins get to say. None clears the plan, which falls the account back on the server config.
- class flexmeasures.data.schemas.account.AccountRoleSchema(*args, **kwargs)
AccountRole schema, with validations.
- class Meta
- model
alias of
AccountRole
- opts: LoadInstanceMixin.Opts = <flask_marshmallow.sqla.SQLAlchemySchemaOpts object>