Browse Source

add new schemas

Guénaël Muller 6 years ago
parent
commit
c87cf3ceb7
1 changed files with 123 additions and 15 deletions
  1. 123 15
      tracim/views/core_api/schemas.py

+ 123 - 15
tracim/views/core_api/schemas.py View File

16
 from tracim.models.data import UserRoleInWorkspace
16
 from tracim.models.data import UserRoleInWorkspace
17
 
17
 
18
 
18
 
19
-class UserSchema(marshmallow.Schema):
20
-
19
+class UserDigestSchema(marshmallow.Schema):
20
+    """
21
+    Simple user schema
22
+    """
21
     user_id = marshmallow.fields.Int(dump_only=True, example=3)
23
     user_id = marshmallow.fields.Int(dump_only=True, example=3)
22
-    email = marshmallow.fields.Email(
23
-        required=True,
24
-        example='suri.cate@algoo.fr'
24
+    avatar_url = marshmallow.fields.Url(
25
+        allow_none=True,
26
+        example="/api/v2/assets/avatars/suri-cate.jpg",
27
+        description="avatar_url is the url to the image file. "
28
+                    "If no avatar, then set it to null "
29
+                    "(and frontend will interpret this with a default avatar)",
25
     )
30
     )
26
     public_name = marshmallow.fields.String(
31
     public_name = marshmallow.fields.String(
27
         example='Suri Cate',
32
         example='Suri Cate',
28
     )
33
     )
34
+
35
+
36
+class UserSchema(UserDigestSchema):
37
+    """
38
+    Complete user schema
39
+    """
40
+    email = marshmallow.fields.Email(
41
+        required=True,
42
+        example='suri.cate@algoo.fr'
43
+    )
29
     created = marshmallow.fields.DateTime(
44
     created = marshmallow.fields.DateTime(
30
         format='%Y-%m-%dT%H:%M:%SZ',
45
         format='%Y-%m-%dT%H:%M:%SZ',
31
         description='User account creation date',
46
         description='User account creation date',
46
         example="/api/v2/calendar/user/3.ics/",
61
         example="/api/v2/calendar/user/3.ics/",
47
         description="The url for calendar CalDAV direct access",
62
         description="The url for calendar CalDAV direct access",
48
     )
63
     )
49
-    avatar_url = marshmallow.fields.Url(
50
-        allow_none=True,
51
-        example="/api/v2/assets/avatars/suri-cate.jpg",
52
-        description="avatar_url is the url to the image file. "
53
-                    "If no avatar, then set it to null "
54
-                    "(and frontend will interpret this with a default avatar)",
55
-    )
56
     profile = marshmallow.fields.String(
64
     profile = marshmallow.fields.String(
57
         attribute='profile',
65
         attribute='profile',
58
         validate=OneOf(Profile._NAME),
66
         validate=OneOf(Profile._NAME),
62
     class Meta:
70
     class Meta:
63
         description = 'User account of Tracim'
71
         description = 'User account of Tracim'
64
 
72
 
65
-
66
 # Path Schemas
73
 # Path Schemas
67
 
74
 
68
 
75
 
78
     content_id = marshmallow.fields.Int(example=6, required=True)
85
     content_id = marshmallow.fields.Int(example=6, required=True)
79
 
86
 
80
 
87
 
81
-class WorkspaceAndContentIdPathSchema(WorkspaceIdPathSchema, ContentIdPathSchema):
88
+class WorkspaceAndContentIdPathSchema(
89
+    WorkspaceIdPathSchema,
90
+    ContentIdPathSchema
91
+):
82
     @post_load
92
     @post_load
83
     def make_path_object(self, data):
93
     def make_path_object(self, data):
84
         return WorkspaceAndContentPath(**data)
94
         return WorkspaceAndContentPath(**data)
85
 
95
 
86
 
96
 
97
+class CommentsPathSchema(WorkspaceAndContentIdPathSchema):
98
+    comment_id = marshmallow.fields.Int(
99
+        example=6,
100
+        description='id of a comment related to content content_id',
101
+        required=True
102
+    )
103
+
104
+
87
 class FilterContentQuerySchema(marshmallow.Schema):
105
 class FilterContentQuerySchema(marshmallow.Schema):
88
     parent_id = marshmallow.fields.Int(
106
     parent_id = marshmallow.fields.Int(
89
         example=2,
107
         example=2,
116
                     'The reason for this parameter to exist is for example '
134
                     'The reason for this parameter to exist is for example '
117
                     'to allow to show only archived documents'
135
                     'to allow to show only archived documents'
118
     )
136
     )
137
+
119
     @post_load
138
     @post_load
120
     def make_content_filter(self, data):
139
     def make_content_filter(self, data):
121
         return ContentFilter(**data)
140
         return ContentFilter(**data)
335
         validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
354
         validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
336
     )
355
     )
337
     sub_content_types = marshmallow.fields.List(
356
     sub_content_types = marshmallow.fields.List(
338
-        marshmallow.fields.Str,
357
+        marshmallow.fields.String(),
339
         description='list of content types allowed as sub contents. '
358
         description='list of content types allowed as sub contents. '
340
                     'This field is required for folder contents, '
359
                     'This field is required for folder contents, '
341
                     'set it to empty list in other cases'
360
                     'set it to empty list in other cases'
355
                     'for sub-contents. Default is True. '
374
                     'for sub-contents. Default is True. '
356
                     'In first version of the API, this field is always True',
375
                     'In first version of the API, this field is always True',
357
     )
376
     )
377
+
378
+
379
+#####
380
+# Content
381
+#####
382
+
383
+class ContentSchema(ContentDigestSchema):
384
+    current_revision_id = marshmallow.fields.Int(example=12)
385
+    created = marshmallow.fields.DateTime(
386
+        format='%Y-%m-%dT%H:%M:%SZ',
387
+        description='Content creation date',
388
+    )
389
+    author = marshmallow.fields.Nested(UserDigestSchema)
390
+    modified = marshmallow.fields.DateTime(
391
+        format='%Y-%m-%dT%H:%M:%SZ',
392
+        description='date of last modification of content',
393
+    )
394
+    last_modifier = marshmallow.fields.Nested(UserDigestSchema)
395
+
396
+
397
+class ThreadContentSchema(ContentSchema):
398
+    raw_content = marshmallow.fields.String('Description of Thread')
399
+
400
+
401
+class HtmlDocumentContentSchema(ContentSchema):
402
+    raw_content = marshmallow.fields.String('<p>Html page Content !</p>')
403
+
404
+#####
405
+# Revision
406
+#####
407
+
408
+
409
+class RevisionSchema(ContentDigestSchema):
410
+    comments_id = marshmallow.fields.List(marshmallow.fields.Int(example=4))
411
+    revision_id = marshmallow.fields.Int(example=12)
412
+    created = marshmallow.fields.DateTime(
413
+        format='%Y-%m-%dT%H:%M:%SZ',
414
+        description='Content creation date',
415
+    )
416
+    author = marshmallow.fields.Nested(UserDigestSchema)
417
+
418
+
419
+class ThreadRevisionSchema(RevisionSchema):
420
+    raw_content = marshmallow.fields.String('Description of Thread')
421
+
422
+
423
+class HtmlDocumentRevisionSchema(RevisionSchema):
424
+    raw_content = marshmallow.fields.String('<p>Html page Content !</p>')
425
+
426
+
427
+####
428
+
429
+class CommentSchema(marshmallow.Schema):
430
+    content_id = marshmallow.fields.Int(example=6)
431
+    parent_id = marshmallow.fields.Int(example=34)
432
+    raw_content = marshmallow.fields.String(
433
+        example='<p>This is just an html comment !</p>'
434
+    )
435
+    author = marshmallow.fields.Nested(UserDigestSchema)
436
+
437
+
438
+class ContentModifySchema(marshmallow.Schema):
439
+    label = marshmallow.fields.String(
440
+        example='contract for client XXX',
441
+        description='New title of the content'
442
+    )
443
+
444
+
445
+class HtmlDocumentModifySchema(ContentModifySchema):
446
+    raw_content = marshmallow.fields.String('<p>Html page Content !</p>')
447
+
448
+
449
+class ThreadModifySchema(ContentModifySchema):
450
+    raw_content = marshmallow.fields.String('Description of Thread')
451
+
452
+
453
+class SetCommentSchema(marshmallow.Schema):
454
+    raw_content = marshmallow.fields.String(
455
+        example='<p>This is just an html comment !</p>'
456
+    )
457
+
458
+
459
+class SetContentStatusSchema(marshmallow.Schema):
460
+    status = marshmallow.fields.Str(
461
+        example='closed-deprecated',
462
+        validate=OneOf([status.slug for status in CONTENT_DEFAULT_STATUS]),
463
+        description='this slug is found in content_type available statuses',
464
+        default=open_status
465
+    )