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
         self.status = status
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
     def __init__(
117
     def __init__(
131
             self,
118
             self,

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

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

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

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

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

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

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

2
 import marshmallow
2
 import marshmallow
3
 from marshmallow import post_load
3
 from marshmallow import post_load
4
 from marshmallow.validate import OneOf
4
 from marshmallow.validate import OneOf
5
-from marshmallow.validate import Equal
6
 
5
 
7
 from tracim.lib.utils.utils import DATETIME_FORMAT
6
 from tracim.lib.utils.utils import DATETIME_FORMAT
8
 from tracim.models.auth import Profile
7
 from tracim.models.auth import Profile
11
 from tracim.models.contents import ContentTypeLegacy as ContentType
10
 from tracim.models.contents import ContentTypeLegacy as ContentType
12
 from tracim.models.contents import ContentStatusLegacy as ContentStatus
11
 from tracim.models.contents import ContentStatusLegacy as ContentStatus
13
 from tracim.models.context_models import ContentCreation
12
 from tracim.models.context_models import ContentCreation
14
-from tracim.models.context_models import SetContentStatus
15
 from tracim.models.context_models import CommentCreation
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
 from tracim.models.context_models import CommentPath
16
 from tracim.models.context_models import CommentPath
17
 from tracim.models.context_models import MoveParams
17
 from tracim.models.context_models import MoveParams
18
 from tracim.models.context_models import WorkspaceAndContentPath
18
 from tracim.models.context_models import WorkspaceAndContentPath
19
 from tracim.models.context_models import ContentFilter
19
 from tracim.models.context_models import ContentFilter
20
 from tracim.models.context_models import LoginCredentials
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
 from tracim.models.data import UserRoleInWorkspace
21
 from tracim.models.data import UserRoleInWorkspace
24
 
22
 
25
 
23
 
407
     last_modifier = marshmallow.fields.Nested(UserDigestSchema)
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
 # Revision
419
 # Revision
437
     author = marshmallow.fields.Nested(UserDigestSchema)
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
 class CommentSchema(marshmallow.Schema):
437
 class CommentSchema(marshmallow.Schema):
459
     content_id = marshmallow.fields.Int(example=6)
438
     content_id = marshmallow.fields.Int(example=6)
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
     @post_load
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
 class SetContentStatusSchema(marshmallow.Schema):
474
 class SetContentStatusSchema(marshmallow.Schema):