Skip to content

Commit

Permalink
feat(api): add Organism schema and add it to User
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Vergez authored and bouttier committed Jan 4, 2024
1 parent 63f5b86 commit 4b05b88
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/pypnusershub/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
from pypnusershub.db.models import User, Organisme


class OrganismeSchema(SmartRelationshipsMixin, ma.SQLAlchemyAutoSchema):
class Meta:
model = Organisme
load_instance = True
sqla_session = db.session


class UserSchema(SmartRelationshipsMixin, ma.SQLAlchemyAutoSchema):
class Meta:
model = User
Expand All @@ -17,17 +24,11 @@ class Meta:
max_level_profil = fields.Integer()
nom_complet = fields.String()
groups = fields.Nested(lambda: UserSchema, many=True)
organisme = fields.Nested(OrganismeSchema)

# TODO: remove this and fix usage of the schema
@pre_load
def make_observer(self, data, **kwargs):
if isinstance(data, int):
return dict({"id_role": data})
return data


class OrganismeSchema(SmartRelationshipsMixin, ma.SQLAlchemyAutoSchema):
class Meta:
model = Organisme
load_instance = True
sqla_session = db.session

0 comments on commit 4b05b88

Please sign in to comment.