schemas.py 3.0KB

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