schemas.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 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
  37. class WorkspaceMenuEntrySchema(marshmallow.Schema):
  38. slug = marshmallow.fields.String()
  39. label = marshmallow.fields.String()
  40. route = marshmallow.fields.String()
  41. hexcolor = marshmallow.fields.String()
  42. icon = marshmallow.fields.String()
  43. class WorkspaceSchema(marshmallow.Schema):
  44. id = marshmallow.fields.Int()
  45. slug = marshmallow.fields.String()
  46. label = marshmallow.fields.String()
  47. description = marshmallow.fields.String()
  48. sidebar_entries = marshmallow.fields.Nested(
  49. WorkspaceMenuEntrySchema,
  50. many=True,
  51. )
  52. class WorkspaceDigestSchema(marshmallow.Schema):
  53. id = marshmallow.fields.Int()
  54. label = marshmallow.fields.String()
  55. sidebar_entries = marshmallow.fields.Nested(
  56. WorkspaceMenuEntrySchema,
  57. many=True,
  58. )
  59. class WorkspaceMemberSchema(marshmallow.Schema):
  60. role = marshmallow.fields.String()
  61. user_id = marshmallow.fields.Int()
  62. workspace_id = marshmallow.fields.Int()
  63. # TODO user
  64. class ApplicationConfigSchema(marshmallow.Schema):
  65. pass
  66. # TODO
  67. class ApplicationSchema(marshmallow.Schema):
  68. label = marshmallow.fields.String()
  69. slug = marshmallow.fields.String()
  70. icon = marshmallow.fields.String()
  71. hexcolor = marshmallow.fields.String()
  72. is_active = marshmallow.fields.Boolean()
  73. config = marshmallow.fields.Nested(
  74. ApplicationConfigSchema,
  75. )