schemas.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # coding=utf-8
  2. import marshmallow
  3. from marshmallow import post_load
  4. from tracim.models.context_models import LoginCredentials, UserInContext
  5. class ProfileSchema(marshmallow.Schema):
  6. id = marshmallow.fields.Int(dump_only=True)
  7. slug = marshmallow.fields.String(attribute='name')
  8. class UserSchema(marshmallow.Schema):
  9. user_id = marshmallow.fields.Int(dump_only=True)
  10. email = marshmallow.fields.Email(required=True)
  11. display_name = marshmallow.fields.String()
  12. created = marshmallow.fields.DateTime(format='iso8601')
  13. is_active = marshmallow.fields.Bool()
  14. # TODO - G.M - 17-04-2018 - Restrict timezone values
  15. timezone = marshmallow.fields.String()
  16. # TODO - G.M - 17-04-2018 - check this, relative url allowed ?
  17. caldav_url = marshmallow.fields.Url(
  18. allow_none=True,
  19. relative=True,
  20. attribute='calendar_url'
  21. )
  22. avatar_url = marshmallow.fields.Url(allow_none=True)
  23. profile = marshmallow.fields.Nested(
  24. ProfileSchema,
  25. many=False,
  26. )
  27. class BasicAuthSchema(marshmallow.Schema):
  28. email = marshmallow.fields.Email(required=True)
  29. password = marshmallow.fields.String(required=True, load_only=True)
  30. @post_load
  31. def make_login(self, data):
  32. return LoginCredentials(**data)
  33. class LoginOutputHeaders(marshmallow.Schema):
  34. expire_after = marshmallow.fields.String()
  35. class NoContentSchema(marshmallow.Schema):
  36. pass