schemas.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # coding=utf-8
  2. import marshmallow
  3. from marshmallow import post_load
  4. from tracim.models.context_models import LoginCredentials
  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 UserIdPathSchema(marshmallow.Schema):
  28. user_id = marshmallow.fields.Int()
  29. class BasicAuthSchema(marshmallow.Schema):
  30. email = marshmallow.fields.Email(required=True)
  31. password = marshmallow.fields.String(required=True, load_only=True)
  32. @post_load
  33. def make_login(self, data):
  34. return LoginCredentials(**data)
  35. class LoginOutputHeaders(marshmallow.Schema):
  36. expire_after = marshmallow.fields.String()
  37. class NoContentSchema(marshmallow.Schema):
  38. pass
  39. class WorkspaceMenuEntrySchema(marshmallow.Schema):
  40. slug = marshmallow.fields.String()
  41. label = marshmallow.fields.String()
  42. route = marshmallow.fields.String()
  43. hexcolor = marshmallow.fields.String()
  44. icon = marshmallow.fields.String()
  45. class WorkspaceSchema(marshmallow.Schema):
  46. id = marshmallow.fields.Int()
  47. slug = marshmallow.fields.String()
  48. label = marshmallow.fields.String()
  49. description = marshmallow.fields.String()
  50. sidebar_entries = marshmallow.fields.Nested(
  51. WorkspaceMenuEntrySchema,
  52. many=True,
  53. )
  54. class WorkspaceDigestSchema(marshmallow.Schema):
  55. id = marshmallow.fields.Int()
  56. label = marshmallow.fields.String()
  57. sidebar_entries = marshmallow.fields.Nested(
  58. WorkspaceMenuEntrySchema,
  59. many=True,
  60. )
  61. class WorkspaceMemberSchema(marshmallow.Schema):
  62. role = marshmallow.fields.String()
  63. user_id = marshmallow.fields.Int()
  64. workspace_id = marshmallow.fields.Int()
  65. # TODO user
  66. class ApplicationConfigSchema(marshmallow.Schema):
  67. pass
  68. # TODO
  69. class ApplicationSchema(marshmallow.Schema):
  70. label = marshmallow.fields.String()
  71. slug = marshmallow.fields.String()
  72. icon = marshmallow.fields.String()
  73. hexcolor = marshmallow.fields.String()
  74. is_active = marshmallow.fields.Boolean()
  75. config = marshmallow.fields.Nested(
  76. ApplicationConfigSchema,
  77. )