|
@@ -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):
|