API

Schemas

class sweetrpg_model_core.schema.base.BaseSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool = False, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Base type for schema classes. Inherit from this type for database schema objects to gain ID and date conversion pre-load functionality, and to have ID and audit fields setup automatically.

class Meta[source]
unknown = 'exclude'
_abc_impl = <_abc._abc_data object>
_declared_fields: Dict[str, ma_fields.Field] = {'created_at': <fields.DateTime(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=True, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid {obj_type}.', 'invalid_awareness': 'Not a valid {awareness} {obj_type}.', 'format': '"{input}" cannot be formatted as a {obj_type}.'})>, 'created_by': <fields.String(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=True, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'})>, 'deleted_at': <fields.DateTime(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=False, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=True, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid {obj_type}.', 'invalid_awareness': 'Not a valid {awareness} {obj_type}.', 'format': '"{input}" cannot be formatted as a {obj_type}.'})>, 'deleted_by': <fields.String(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=False, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=True, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'})>, 'id': <fields.String(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=False, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'})>, 'updated_at': <fields.DateTime(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=True, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid {obj_type}.', 'invalid_awareness': 'Not a valid {awareness} {obj_type}.', 'format': '"{input}" cannot be formatted as a {obj_type}.'})>, 'updated_by': <fields.String(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=True, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'})>}
_hooks: Dict[types.Tag, List[str]] = {('post_load', False): ['make_object'], ('pre_load', False): ['handle_dates', 'handle_id']}
handle_dates(in_data, **kwargs)[source]

Converts date/time value to an ISO formatted string.

handle_id(in_data, **kwargs)[source]

Converts _id into id

make_object(data, **kwargs)[source]

Create a model object from the provided data.

Parameters:

data – A dictionary of data to populate the model object.

Returns:

An instance of the model_class.

opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>

Converters

sweetrpg_model_core.convert.date.to_datetime(value, tz=None, attr=None, data=None, **kwargs)[source]

Deserializes a database value to a Python datetime. This function can be used as a callback for the Marshmallow fields.Function field type.

Parameters:
  • value (any) – The source value to convert to a Python datetime object. This can be a MongoDB bson.timestamp.Timestamp, an ISO-formatted date/time string, or a UTC unix timestamp value.

  • attr (str) – The name of the attribute being deserialized.

  • data (object) – The object associated.

  • kwargs (dict) –

Return datetime.datetime:

Python datetime object

sweetrpg_model_core.convert.date.to_timestamp(value, attr=None, obj=None, **kwargs)[source]

Serialize an object value to a MongoDB timestamp. This function can be used as a callback for the Marshmallow fields.Function field type.

Parameters:
  • value (any) – The source value to convert to a MongoDB bson.timestamp.Timestamp. This can be a datetime object, or a time/increment tuple.

  • attr (str) – The name of the attribute being serialized.

  • obj (object) – The object associated.

  • kwargs (dict) –

Return bson.timestamp.Timestamp:

MongoDB Timestamp object