flexmeasures.data.schemas.account

Classes

class flexmeasures.data.schemas.account.AccountIdField(*, strict: bool = False, as_string: bool = False, **kwargs: Unpack[_BaseFieldKwargs])

Field that deserializes to an Account and serializes back to an integer.

_deserialize(value: Any, attr, data, **kwargs) Account

Turn an account id into an Account.

_serialize(value: Account, attr, obj, **kwargs)

Turn an Account into a source id.

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, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | 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 42 and [42, 99] are accepted. Always deserializes to a list of Account instances.

The field is intentionally expressed as a union of integer and array[integer] rather than always requiring a list, so that future OpenAPI generation can emit a oneOf schema for it.

_deserialize(value: Any, attr, data, **kwargs) list[Account]

Deserialize value. Concrete Field classes 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 **kwargs to signature.

_serialize(value: Any, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes 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.AccountRoleSchema(*args, **kwargs)

AccountRole schema, with validations.

class Meta
model

alias of AccountRole

opts: LoadInstanceMixin.Opts = <flask_marshmallow.sqla.SQLAlchemySchemaOpts object>
class flexmeasures.data.schemas.account.AccountSchema(*args, **kwargs)

Account schema, with validations.

class Meta
model

alias of Account

opts: LoadInstanceMixin.Opts = <flask_marshmallow.sqla.SQLAlchemySchemaOpts object>