Sfoglia il codice sorgente

use always contentType and contentStatus class + accept special(comment,event) content_type in output schema

Guénaël Muller 6 anni fa
parent
commit
a7de214c88

+ 16 - 12
tracim/views/core_api/schemas.py Vedi File

@@ -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,

+ 4 - 3
tracim/views/core_api/system_controller.py Vedi File

@@ -5,7 +5,7 @@ from tracim.exceptions import InsufficientUserProfile
5 5
 from tracim.lib.utils.authorization import require_profile
6 6
 from tracim.models import Group
7 7
 from tracim.models.applications import applications
8
-from tracim.models.contents import CONTENT_DEFAULT_TYPE
8
+from tracim.models.contents import ContentTypeLegacy as ContentType
9 9
 
10 10
 try:  # Python 3.5+
11 11
     from http import HTTPStatus
@@ -42,8 +42,9 @@ class SystemController(Controller):
42 42
         """
43 43
         Get list of alls content types availables in this tracim instance.
44 44
         """
45
-
46
-        return CONTENT_DEFAULT_TYPE
45
+        content_types_slugs = ContentType.allowed_types_for_folding()
46
+        content_types = [ContentType(slug) for slug in content_types_slugs]
47
+        return content_types
47 48
 
48 49
     def bind(self, configurator: Configurator) -> None:
49 50
         """