|
@@ -2,13 +2,14 @@
|
2
|
2
|
import marshmallow
|
3
|
3
|
from marshmallow import post_load
|
4
|
4
|
from marshmallow.validate import OneOf
|
|
5
|
+from marshmallow.validate import Equal
|
5
|
6
|
|
6
|
7
|
from tracim.lib.utils.utils import DATETIME_FORMAT
|
7
|
8
|
from tracim.models.auth import Profile
|
8
|
|
-from tracim.models.contents import CONTENT_DEFAULT_TYPE
|
9
|
|
-from tracim.models.contents import CONTENT_DEFAULT_STATUS
|
10
|
9
|
from tracim.models.contents import GlobalStatus
|
11
|
10
|
from tracim.models.contents import open_status
|
|
11
|
+from tracim.models.contents import ContentTypeLegacy as ContentType
|
|
12
|
+from tracim.models.contents import ContentStatusLegacy as ContentStatus
|
12
|
13
|
from tracim.models.context_models import ContentCreation
|
13
|
14
|
from tracim.models.context_models import SetContentStatus
|
14
|
15
|
from tracim.models.context_models import CommentCreation
|
|
@@ -286,7 +287,7 @@ class StatusSchema(marshmallow.Schema):
|
286
|
287
|
class ContentTypeSchema(marshmallow.Schema):
|
287
|
288
|
slug = marshmallow.fields.String(
|
288
|
289
|
example='pagehtml',
|
289
|
|
- validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
|
|
290
|
+ validate=OneOf(ContentType.allowed_types()),
|
290
|
291
|
)
|
291
|
292
|
fa_icon = marshmallow.fields.String(
|
292
|
293
|
example='fa-file-text-o',
|
|
@@ -338,7 +339,7 @@ class ContentCreationSchema(marshmallow.Schema):
|
338
|
339
|
)
|
339
|
340
|
content_type = marshmallow.fields.String(
|
340
|
341
|
example='html-documents',
|
341
|
|
- validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
|
|
342
|
+ validate=OneOf(ContentType.allowed_types_for_folding()), # nopep8
|
342
|
343
|
)
|
343
|
344
|
|
344
|
345
|
@post_load
|
|
@@ -360,17 +361,20 @@ class ContentDigestSchema(marshmallow.Schema):
|
360
|
361
|
label = marshmallow.fields.Str(example='Intervention Report 12')
|
361
|
362
|
content_type = marshmallow.fields.Str(
|
362
|
363
|
example='html-documents',
|
363
|
|
- validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
|
|
364
|
+ validate=OneOf(ContentType.allowed_types()),
|
364
|
365
|
)
|
365
|
366
|
sub_content_types = marshmallow.fields.List(
|
366
|
|
- marshmallow.fields.String(),
|
|
367
|
+ marshmallow.fields.String(
|
|
368
|
+ example='html-content',
|
|
369
|
+ validate=OneOf(ContentType.allowed_types())
|
|
370
|
+ ),
|
367
|
371
|
description='list of content types allowed as sub contents. '
|
368
|
372
|
'This field is required for folder contents, '
|
369
|
373
|
'set it to empty list in other cases'
|
370
|
374
|
)
|
371
|
375
|
status = marshmallow.fields.Str(
|
372
|
376
|
example='closed-deprecated',
|
373
|
|
- validate=OneOf([status.slug for status in CONTENT_DEFAULT_STATUS]),
|
|
377
|
+ validate=OneOf(ContentStatus.allowed_values()),
|
374
|
378
|
description='this slug is found in content_type available statuses',
|
375
|
379
|
default=open_status
|
376
|
380
|
)
|
|
@@ -406,7 +410,7 @@ class ContentSchema(ContentDigestSchema):
|
406
|
410
|
class ThreadContentSchema(ContentSchema):
|
407
|
411
|
content_type = marshmallow.fields.Str(
|
408
|
412
|
example='thread',
|
409
|
|
- validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
|
|
413
|
+ validate=Equal(ContentType('thread').slug)
|
410
|
414
|
)
|
411
|
415
|
raw_content = marshmallow.fields.String('Description of Thread')
|
412
|
416
|
|
|
@@ -414,7 +418,7 @@ class ThreadContentSchema(ContentSchema):
|
414
|
418
|
class HtmlDocumentContentSchema(ContentSchema):
|
415
|
419
|
content_type = marshmallow.fields.Str(
|
416
|
420
|
example='html-documents',
|
417
|
|
- validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
|
|
421
|
+ validate=Equal(ContentType('html-documents').slug),
|
418
|
422
|
)
|
419
|
423
|
raw_content = marshmallow.fields.String('<p>Html page Content!</p>')
|
420
|
424
|
|
|
@@ -436,7 +440,7 @@ class RevisionSchema(ContentDigestSchema):
|
436
|
440
|
class ThreadRevisionSchema(RevisionSchema):
|
437
|
441
|
content_type = marshmallow.fields.Str(
|
438
|
442
|
example='thread',
|
439
|
|
- validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
|
|
443
|
+ validate=Equal(ContentType('thread').slug),
|
440
|
444
|
)
|
441
|
445
|
raw_content = marshmallow.fields.String('Description of Thread')
|
442
|
446
|
|
|
@@ -444,7 +448,7 @@ class ThreadRevisionSchema(RevisionSchema):
|
444
|
448
|
class HtmlDocumentRevisionSchema(RevisionSchema):
|
445
|
449
|
content_type = marshmallow.fields.Str(
|
446
|
450
|
example='html-documents',
|
447
|
|
- validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
|
|
451
|
+ validate=Equal(ContentType('html-documents').slug),
|
448
|
452
|
)
|
449
|
453
|
raw_content = marshmallow.fields.String('<p>Html page Content!</p>')
|
450
|
454
|
|
|
@@ -500,7 +504,7 @@ class SetCommentSchema(marshmallow.Schema):
|
500
|
504
|
class SetContentStatusSchema(marshmallow.Schema):
|
501
|
505
|
status = marshmallow.fields.Str(
|
502
|
506
|
example='closed-deprecated',
|
503
|
|
- validate=OneOf([status.slug for status in CONTENT_DEFAULT_STATUS]),
|
|
507
|
+ validate=OneOf(ContentStatus.allowed_values()),
|
504
|
508
|
description='this slug is found in content_type available statuses',
|
505
|
509
|
default=open_status,
|
506
|
510
|
required=True,
|