Quellcode durchsuchen

use same schema/model for textbased content

Guénaël Muller vor 6 Jahren
Ursprung
Commit
0cadc3ef93

+ 2 - 15
tracim/models/context_models.py Datei anzeigen

@@ -110,22 +110,9 @@ class SetContentStatus(object):
110 110
         self.status = status
111 111
 
112 112
 
113
-class HTMLDocumentUpdate(object):
113
+class TextBasedContentUpdate(object):
114 114
     """
115
-    Html Document update model
116
-    """
117
-    def __init__(
118
-            self,
119
-            label: str,
120
-            raw_content: str,
121
-    ) -> None:
122
-        self.label = label
123
-        self.raw_content = raw_content
124
-
125
-
126
-class ThreadUpdate(object):
127
-    """
128
-    Thread update model
115
+    TextBasedContent update model
129 116
     """
130 117
     def __init__(
131 118
             self,

+ 2 - 2
tracim/views/contents_api/comment_controller.py Datei anzeigen

@@ -39,7 +39,7 @@ class CommentController(Controller):
39 39
     @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
40 40
     @require_workspace_role(UserRoleInWorkspace.READER)
41 41
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
42
-    @hapic.output_body(CommentSchema(many=True),)
42
+    @hapic.output_body(CommentSchema(many=True))
43 43
     def content_comments(self, context, request: TracimRequest, hapic_data=None):
44 44
         """
45 45
         Get all comments related to a content in asc order (first is the oldest)
@@ -70,7 +70,7 @@ class CommentController(Controller):
70 70
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
71 71
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
72 72
     @hapic.input_body(SetCommentSchema())
73
-    @hapic.output_body(CommentSchema(),)
73
+    @hapic.output_body(CommentSchema())
74 74
     def add_comment(self, context, request: TracimRequest, hapic_data=None):
75 75
         """
76 76
         Add new comment

+ 7 - 7
tracim/views/contents_api/html_document_controller.py Datei anzeigen

@@ -15,10 +15,10 @@ from tracim import TracimRequest
15 15
 from tracim.extensions import hapic
16 16
 from tracim.lib.core.content import ContentApi
17 17
 from tracim.views.controllers import Controller
18
-from tracim.views.core_api.schemas import HtmlDocumentContentSchema
19
-from tracim.views.core_api.schemas import HtmlDocumentRevisionSchema
18
+from tracim.views.core_api.schemas import TextBasedContentSchema
19
+from tracim.views.core_api.schemas import TextBasedRevisionSchema
20
+from tracim.views.core_api.schemas import TextBasedContentModifySchema
20 21
 from tracim.views.core_api.schemas import SetContentStatusSchema
21
-from tracim.views.core_api.schemas import HtmlDocumentModifySchema
22 22
 from tracim.views.core_api.schemas import WorkspaceAndContentIdPathSchema
23 23
 from tracim.views.core_api.schemas import NoContentSchema
24 24
 from tracim.lib.utils.authorization import require_content_types
@@ -48,7 +48,7 @@ class HTMLDocumentController(Controller):
48 48
     @require_workspace_role(UserRoleInWorkspace.READER)
49 49
     @require_content_types([html_documents_type])
50 50
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
51
-    @hapic.output_body(HtmlDocumentContentSchema())
51
+    @hapic.output_body(TextBasedContentSchema())
52 52
     def get_html_document(self, context, request: TracimRequest, hapic_data=None) -> ContentInContext:  # nopep8
53 53
         """
54 54
         Get html document content
@@ -73,8 +73,8 @@ class HTMLDocumentController(Controller):
73 73
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
74 74
     @require_content_types([html_documents_type])
75 75
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
76
-    @hapic.input_body(HtmlDocumentModifySchema())
77
-    @hapic.output_body(HtmlDocumentContentSchema())
76
+    @hapic.input_body(TextBasedContentModifySchema())
77
+    @hapic.output_body(TextBasedContentSchema())
78 78
     def update_html_document(self, context, request: TracimRequest, hapic_data=None) -> ContentInContext:  # nopep8
79 79
         """
80 80
         update_html_document
@@ -111,7 +111,7 @@ class HTMLDocumentController(Controller):
111 111
     @require_workspace_role(UserRoleInWorkspace.READER)
112 112
     @require_content_types([html_documents_type])
113 113
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
114
-    @hapic.output_body(HtmlDocumentRevisionSchema(many=True))
114
+    @hapic.output_body(TextBasedRevisionSchema(many=True))
115 115
     def get_html_document_revisions(
116 116
             self,
117 117
             context,

+ 7 - 7
tracim/views/contents_api/threads_controller.py Datei anzeigen

@@ -14,10 +14,10 @@ from tracim import TracimRequest
14 14
 from tracim.extensions import hapic
15 15
 from tracim.lib.core.content import ContentApi
16 16
 from tracim.views.controllers import Controller
17
-from tracim.views.core_api.schemas import ThreadContentSchema
18
-from tracim.views.core_api.schemas import ThreadRevisionSchema
17
+from tracim.views.core_api.schemas import TextBasedContentSchema
18
+from tracim.views.core_api.schemas import TextBasedRevisionSchema
19 19
 from tracim.views.core_api.schemas import SetContentStatusSchema
20
-from tracim.views.core_api.schemas import ThreadModifySchema
20
+from tracim.views.core_api.schemas import TextBasedContentModifySchema
21 21
 from tracim.views.core_api.schemas import WorkspaceAndContentIdPathSchema
22 22
 from tracim.views.core_api.schemas import NoContentSchema
23 23
 from tracim.lib.utils.authorization import require_content_types
@@ -46,7 +46,7 @@ class ThreadController(Controller):
46 46
     @require_workspace_role(UserRoleInWorkspace.READER)
47 47
     @require_content_types([thread_type])
48 48
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
49
-    @hapic.output_body(ThreadContentSchema())
49
+    @hapic.output_body(TextBasedContentSchema())
50 50
     def get_thread(self, context, request: TracimRequest, hapic_data=None) -> ContentInContext:  # nopep8
51 51
         """
52 52
         Get thread content
@@ -71,8 +71,8 @@ class ThreadController(Controller):
71 71
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
72 72
     @require_content_types([thread_type])
73 73
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
74
-    @hapic.input_body(ThreadModifySchema())
75
-    @hapic.output_body(ThreadContentSchema())
74
+    @hapic.input_body(TextBasedContentModifySchema())
75
+    @hapic.output_body(TextBasedContentSchema())
76 76
     def update_thread(self, context, request: TracimRequest, hapic_data=None) -> ContentInContext:  # nopep8
77 77
         """
78 78
         update thread
@@ -109,7 +109,7 @@ class ThreadController(Controller):
109 109
     @require_workspace_role(UserRoleInWorkspace.READER)
110 110
     @require_content_types([thread_type])
111 111
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
112
-    @hapic.output_body(ThreadRevisionSchema(many=True))
112
+    @hapic.output_body(TextBasedRevisionSchema(many=True))
113 113
     def get_thread_revisions(
114 114
             self,
115 115
             context,

+ 24 - 54
tracim/views/core_api/schemas.py Datei anzeigen

@@ -2,7 +2,6 @@
2 2
 import marshmallow
3 3
 from marshmallow import post_load
4 4
 from marshmallow.validate import OneOf
5
-from marshmallow.validate import Equal
6 5
 
7 6
 from tracim.lib.utils.utils import DATETIME_FORMAT
8 7
 from tracim.models.auth import Profile
@@ -11,15 +10,14 @@ from tracim.models.contents import open_status
11 10
 from tracim.models.contents import ContentTypeLegacy as ContentType
12 11
 from tracim.models.contents import ContentStatusLegacy as ContentStatus
13 12
 from tracim.models.context_models import ContentCreation
14
-from tracim.models.context_models import SetContentStatus
15 13
 from tracim.models.context_models import CommentCreation
14
+from tracim.models.context_models import TextBasedContentUpdate
15
+from tracim.models.context_models import SetContentStatus
16 16
 from tracim.models.context_models import CommentPath
17 17
 from tracim.models.context_models import MoveParams
18 18
 from tracim.models.context_models import WorkspaceAndContentPath
19 19
 from tracim.models.context_models import ContentFilter
20 20
 from tracim.models.context_models import LoginCredentials
21
-from tracim.models.context_models import HTMLDocumentUpdate
22
-from tracim.models.context_models import ThreadUpdate
23 21
 from tracim.models.data import UserRoleInWorkspace
24 22
 
25 23
 
@@ -407,20 +405,15 @@ class ContentSchema(ContentDigestSchema):
407 405
     last_modifier = marshmallow.fields.Nested(UserDigestSchema)
408 406
 
409 407
 
410
-class ThreadContentSchema(ContentSchema):
411
-    content_type = marshmallow.fields.Str(
412
-        example='thread',
413
-        validate=Equal(ContentType('thread').slug)
408
+class TextBasedDataAbstractSchema(marshmallow.Schema):
409
+    raw_content = marshmallow.fields.String(
410
+        description='Content of the object, may be raw text or <b>html</b> for example'  # nopep8
414 411
     )
415
-    raw_content = marshmallow.fields.String('Description of Thread')
416 412
 
417 413
 
418
-class HtmlDocumentContentSchema(ContentSchema):
419
-    content_type = marshmallow.fields.Str(
420
-        example='html-documents',
421
-        validate=Equal(ContentType('html-documents').slug),
422
-    )
423
-    raw_content = marshmallow.fields.String('<p>Html page Content!</p>')
414
+class TextBasedContentSchema(ContentSchema, TextBasedDataAbstractSchema):
415
+    pass
416
+
424 417
 
425 418
 #####
426 419
 # Revision
@@ -437,23 +430,9 @@ class RevisionSchema(ContentDigestSchema):
437 430
     author = marshmallow.fields.Nested(UserDigestSchema)
438 431
 
439 432
 
440
-class ThreadRevisionSchema(RevisionSchema):
441
-    content_type = marshmallow.fields.Str(
442
-        example='thread',
443
-        validate=Equal(ContentType('thread').slug),
444
-    )
445
-    raw_content = marshmallow.fields.String('Description of Thread')
446
-
447
-
448
-class HtmlDocumentRevisionSchema(RevisionSchema):
449
-    content_type = marshmallow.fields.Str(
450
-        example='html-documents',
451
-        validate=Equal(ContentType('html-documents').slug),
452
-    )
453
-    raw_content = marshmallow.fields.String('<p>Html page Content!</p>')
454
-
433
+class TextBasedRevisionSchema(RevisionSchema, TextBasedDataAbstractSchema):
434
+    pass
455 435
 
456
-####
457 436
 
458 437
 class CommentSchema(marshmallow.Schema):
459 438
     content_id = marshmallow.fields.Int(example=6)
@@ -468,37 +447,28 @@ class CommentSchema(marshmallow.Schema):
468 447
     )
469 448
 
470 449
 
471
-class ContentModifySchema(marshmallow.Schema):
472
-    label = marshmallow.fields.String(
473
-        example='contract for client XXX',
474
-        description='New title of the content'
450
+class SetCommentSchema(marshmallow.Schema):
451
+    raw_content = marshmallow.fields.String(
452
+        example='<p>This is just an html comment !</p>'
475 453
     )
476 454
 
455
+    @post_load()
456
+    def create_comment(self, data):
457
+        return CommentCreation(**data)
477 458
 
478
-class HtmlDocumentModifySchema(ContentModifySchema):
479
-    raw_content = marshmallow.fields.String('<p>Html page Content!</p>')
480
-
481
-    @post_load
482
-    def html_document_update(self, data):
483
-        return HTMLDocumentUpdate(**data)
484
-
485
-
486
-class ThreadModifySchema(ContentModifySchema):
487
-    raw_content = marshmallow.fields.String('Description of Thread')
488 459
 
489
-    @post_load
490
-    def thread_update(self, data):
491
-        return ThreadUpdate(**data)
460
+class ContentModifyAbstractSchema(marshmallow.Schema):
461
+    label = marshmallow.fields.String(
462
+        example='contract for client XXX',
463
+        description='New title of the content'
464
+    )
492 465
 
493 466
 
494
-class SetCommentSchema(marshmallow.Schema):
495
-    raw_content = marshmallow.fields.String(
496
-        example='<p>This is just an html comment !</p>'
497
-    )
467
+class TextBasedContentModifySchema(ContentModifyAbstractSchema, TextBasedDataAbstractSchema):  # nopep8
498 468
 
499 469
     @post_load
500
-    def create_comment(self, data):
501
-        return CommentCreation(**data)
470
+    def text_based_content_update(self, data):
471
+        return TextBasedContentUpdate(**data)
502 472
 
503 473
 
504 474
 class SetContentStatusSchema(marshmallow.Schema):