geonature.core.gn_permissions.schemas ===================================== .. py:module:: geonature.core.gn_permissions.schemas Classes ------- .. autoapisummary:: geonature.core.gn_permissions.schemas.PermActionSchema geonature.core.gn_permissions.schemas.PermObjectSchema geonature.core.gn_permissions.schemas.PermissionSchema geonature.core.gn_permissions.schemas.PermissionAvailableSchema Module Contents --------------- .. py:class:: PermActionSchema(*args, **kwargs) Bases: :py:obj:`geonature.utils.env.ma.SQLAlchemyAutoSchema` SQLAlchemyAutoSchema that automatically generates marshmallow fields from a SQLAlchemy model's or table's column. Uses the scoped session from Flask-SQLAlchemy by default. See `marshmallow_sqlalchemy.SQLAlchemyAutoSchema` for more details on the `SQLAlchemyAutoSchema` API. .. py:class:: Meta Options object for a Schema. Example usage: :: from marshmallow import Schema class MySchema(Schema): class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute") .. admonition:: A note on type checking Type checkers will only check the attributes of the `Meta ` class if you explicitly subclass `marshmallow.Schema.Meta`. .. code-block:: python from marshmallow import Schema class MySchema(Schema): # Not checked by type checkers class Meta: additional = True class MySchema2(Schema): # Type checkers will check attributes class Meta(Schema.Opts): additional = True # Incompatible types in assignment .. versionremoved:: 3.0.0b7 Remove ``strict``. .. versionadded:: 3.0.0b12 Add `unknown`. .. versionchanged:: 3.0.0b17 Rename ``dateformat`` to `datetimeformat`. .. versionadded:: 3.9.0 Add `timeformat`. .. versionchanged:: 3.26.0 Deprecate ``ordered``. Field order is preserved by default. .. versionremoved:: 4.0.0 Remove ``ordered``. .. py:attribute:: model .. py:attribute:: include_fk :value: True .. py:class:: PermObjectSchema(*args, **kwargs) Bases: :py:obj:`geonature.utils.env.ma.SQLAlchemyAutoSchema` SQLAlchemyAutoSchema that automatically generates marshmallow fields from a SQLAlchemy model's or table's column. Uses the scoped session from Flask-SQLAlchemy by default. See `marshmallow_sqlalchemy.SQLAlchemyAutoSchema` for more details on the `SQLAlchemyAutoSchema` API. .. py:class:: Meta Options object for a Schema. Example usage: :: from marshmallow import Schema class MySchema(Schema): class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute") .. admonition:: A note on type checking Type checkers will only check the attributes of the `Meta ` class if you explicitly subclass `marshmallow.Schema.Meta`. .. code-block:: python from marshmallow import Schema class MySchema(Schema): # Not checked by type checkers class Meta: additional = True class MySchema2(Schema): # Type checkers will check attributes class Meta(Schema.Opts): additional = True # Incompatible types in assignment .. versionremoved:: 3.0.0b7 Remove ``strict``. .. versionadded:: 3.0.0b12 Add `unknown`. .. versionchanged:: 3.0.0b17 Rename ``dateformat`` to `datetimeformat`. .. versionadded:: 3.9.0 Add `timeformat`. .. versionchanged:: 3.26.0 Deprecate ``ordered``. Field order is preserved by default. .. versionremoved:: 4.0.0 Remove ``ordered``. .. py:attribute:: model .. py:attribute:: include_fk :value: True .. py:class:: PermissionSchema(*args, **kwargs) Bases: :py:obj:`utils_flask_sqla.schema.SmartRelationshipsMixin`, :py:obj:`geonature.utils.env.ma.SQLAlchemyAutoSchema` Marchmallow-sqlalchemy behavior is to search object in database, and if not found, to create a new one. As this schema is not means to create any related object, nested fields are dump only (use the FK to set the value). For m2m fields, as it is not possible to load the FK which is in another table, we let the user provide m2m models PK, but we have validation hooks which verify that related models exists and have not been created by marchmallow-sqlalchemy. .. py:class:: Meta Options object for a Schema. Example usage: :: from marshmallow import Schema class MySchema(Schema): class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute") .. admonition:: A note on type checking Type checkers will only check the attributes of the `Meta ` class if you explicitly subclass `marshmallow.Schema.Meta`. .. code-block:: python from marshmallow import Schema class MySchema(Schema): # Not checked by type checkers class Meta: additional = True class MySchema2(Schema): # Type checkers will check attributes class Meta(Schema.Opts): additional = True # Incompatible types in assignment .. versionremoved:: 3.0.0b7 Remove ``strict``. .. versionadded:: 3.0.0b12 Add `unknown`. .. versionchanged:: 3.0.0b17 Rename ``dateformat`` to `datetimeformat`. .. versionadded:: 3.9.0 Add `timeformat`. .. versionchanged:: 3.26.0 Deprecate ``ordered``. Field order is preserved by default. .. versionremoved:: 4.0.0 Remove ``ordered``. .. py:attribute:: model .. py:attribute:: include_fk :value: True .. py:attribute:: load_instance :value: True .. py:attribute:: sqla_session .. py:attribute:: dump_only :value: ('role', 'action', 'module', 'object') .. py:attribute:: role .. py:attribute:: action .. py:attribute:: module .. py:attribute:: object .. py:attribute:: scope_value .. py:attribute:: areas_filter .. py:attribute:: taxons_filter .. py:method:: validate_areas_filter(data, **kwargs) .. py:method:: validate_taxons_filter(data, **kwargs) .. py:class:: PermissionAvailableSchema(*args, **kwargs) Bases: :py:obj:`utils_flask_sqla.schema.SmartRelationshipsMixin`, :py:obj:`geonature.utils.env.ma.SQLAlchemyAutoSchema` This mixin automatically exclude from serialization: * Nested, RelatedList and Related fields * all fields with exclude=True in their metadata (e.g. ``fields.String(metadata={'exclude': True})``) * For SQLAlchemyAutoSchema, all deffered columns Default marshmallow behaviour is to serialize only fields specified in ``only``. This mixin add these: * If they are only Nested fields in ``only``, they are added to serialized fields *along with* default serialized fields. * To serialize Nested fields only and not default serialized fields, add ``"-"`` special value to ``only``. * To add excluded fields (through metadata or deffered fields) to the serialization *in addition* to default serialized fields, use '+field_name' syntax. Examples : .. code-block:: python class FooSchema(SmartRelationshipsMixin): id = fields.Int() name = field.Str() default_excluded_field = fields.Str(metadata={"exclude": True}) relationship = fields.Nested(OtherSchema) # or field.RelatedList() / field.Related() FooSchema().dump() -> {"id": 1, "name": "toto" } FooSchema(only=["id"]).dump() -> {"id": 1} FooSchema(only=["default_excluded_field"]).dump() -> {"default_excluded_field": "test"} FooSchema(only=["+default_excluded_field"]).dump() -> {"id": 1, "name": "toto", "default_excluded_field": "test"} FooSchema(only=["relationship"]).dump() -> {"id": 1, "name": "toto", "relationship": {OtherSchema...} } FooSchema(only=["id", "relationship"]).dump() -> {"id": 1, "relationship": {OtherSchema...}} FooSchema(only=["-", "relationship"]).dump() -> {"relationship": {OtherSchema...}} .. py:class:: Meta Options object for a Schema. Example usage: :: from marshmallow import Schema class MySchema(Schema): class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute") .. admonition:: A note on type checking Type checkers will only check the attributes of the `Meta ` class if you explicitly subclass `marshmallow.Schema.Meta`. .. code-block:: python from marshmallow import Schema class MySchema(Schema): # Not checked by type checkers class Meta: additional = True class MySchema2(Schema): # Type checkers will check attributes class Meta(Schema.Opts): additional = True # Incompatible types in assignment .. versionremoved:: 3.0.0b7 Remove ``strict``. .. versionadded:: 3.0.0b12 Add `unknown`. .. versionchanged:: 3.0.0b17 Rename ``dateformat`` to `datetimeformat`. .. versionadded:: 3.9.0 Add `timeformat`. .. versionchanged:: 3.26.0 Deprecate ``ordered``. Field order is preserved by default. .. versionremoved:: 4.0.0 Remove ``ordered``. .. py:attribute:: model .. py:attribute:: include_fk :value: True .. py:attribute:: load_instance :value: True .. py:attribute:: sqla_session .. py:attribute:: action .. py:attribute:: module .. py:attribute:: object