Code source de pypnusershub.schemas

from marshmallow import pre_load, fields

from utils_flask_sqla.schema import SmartRelationshipsMixin

from pypnusershub.env import ma, db
from pypnusershub.db.models import User, Organisme


[docs] class OrganismeSchema(SmartRelationshipsMixin, ma.SQLAlchemyAutoSchema):
[docs] class Meta:
[docs] model = Organisme
[docs] load_instance = True
[docs] sqla_session = db.session
[docs] class UserSchema(SmartRelationshipsMixin, ma.SQLAlchemyAutoSchema):
[docs] class Meta:
[docs] model = User
[docs] include_fk = True
[docs] load_instance = True
[docs] sqla_session = db.session
[docs] exclude = ("_password", "_password_plus", "champs_addi", "max_level_profil")
[docs] max_level_profil = fields.Integer()
[docs] nom_complet = fields.String()
[docs] groups = fields.Nested(lambda: UserSchema, many=True)
[docs] organisme = fields.Nested(OrganismeSchema)
# TODO: remove this and fix usage of the schema @pre_load
[docs] def make_observer(self, data, **kwargs): if isinstance(data, int): return dict({"id_role": data}) return data