Browse Source

rename content_type_slug and sub_content_type_slug

Guénaël Muller 6 years ago
parent
commit
5cf00321c9

+ 4 - 4
tracim/models/context_models.py View File

64
     def __init__(
64
     def __init__(
65
             self,
65
             self,
66
             label: str,
66
             label: str,
67
-            content_type_slug: str,
67
+            content_type: str,
68
     ):
68
     ):
69
         self.label = label
69
         self.label = label
70
-        self.content_type_slug = content_type_slug
70
+        self.content_type = content_type
71
 
71
 
72
 
72
 
73
 class UserInContext(object):
73
 class UserInContext(object):
290
         return self.content.label
290
         return self.content.label
291
 
291
 
292
     @property
292
     @property
293
-    def content_type_slug(self) -> str:
293
+    def content_type(self) -> str:
294
         return self.content.type
294
         return self.content.type
295
 
295
 
296
     @property
296
     @property
297
-    def sub_content_type_slug(self) -> typing.List[str]:
297
+    def sub_content_types(self) -> typing.List[str]:
298
         return [type.slug for type in self.content.get_allowed_content_types()]
298
         return [type.slug for type in self.content.get_allowed_content_types()]
299
 
299
 
300
     @property
300
     @property

+ 30 - 30
tracim/tests/functional/test_workspaces.py View File

247
         assert content['show_in_ui'] is True
247
         assert content['show_in_ui'] is True
248
         assert content['slug'] == 'tools'
248
         assert content['slug'] == 'tools'
249
         assert content['status_slug'] == 'open'
249
         assert content['status_slug'] == 'open'
250
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
250
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
251
         assert content['workspace_id'] == 1
251
         assert content['workspace_id'] == 1
252
         content = res[1]
252
         content = res[1]
253
         assert content['id'] == 2
253
         assert content['id'] == 2
258
         assert content['show_in_ui'] is True
258
         assert content['show_in_ui'] is True
259
         assert content['slug'] == 'menus'
259
         assert content['slug'] == 'menus'
260
         assert content['status_slug'] == 'open'
260
         assert content['status_slug'] == 'open'
261
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
261
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
262
         assert content['workspace_id'] == 1
262
         assert content['workspace_id'] == 1
263
         content = res[2]
263
         content = res[2]
264
         assert content['id'] == 11
264
         assert content['id'] == 11
269
         assert content['show_in_ui'] is True
269
         assert content['show_in_ui'] is True
270
         assert content['slug'] == 'current-menu'
270
         assert content['slug'] == 'current-menu'
271
         assert content['status_slug'] == 'open'
271
         assert content['status_slug'] == 'open'
272
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
272
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
273
         assert content['workspace_id'] == 1
273
         assert content['workspace_id'] == 1
274
 
274
 
275
     # Root related
275
     # Root related
299
         # TODO - G.M - 30-05-2018 - Check this test
299
         # TODO - G.M - 30-05-2018 - Check this test
300
         assert len(res) == 4
300
         assert len(res) == 4
301
         content = res[1]
301
         content = res[1]
302
-        assert content['content_type_slug'] == 'page'
302
+        assert content['content_type'] == 'page'
303
         assert content['id'] == 15
303
         assert content['id'] == 15
304
         assert content['is_archived'] is False
304
         assert content['is_archived'] is False
305
         assert content['is_deleted'] is False
305
         assert content['is_deleted'] is False
308
         assert content['show_in_ui'] is True
308
         assert content['show_in_ui'] is True
309
         assert content['slug'] == 'new-fruit-salad'
309
         assert content['slug'] == 'new-fruit-salad'
310
         assert content['status_slug'] == 'open'
310
         assert content['status_slug'] == 'open'
311
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
311
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
312
         assert content['workspace_id'] == 3
312
         assert content['workspace_id'] == 3
313
 
313
 
314
         content = res[2]
314
         content = res[2]
315
-        assert content['content_type_slug'] == 'page'
315
+        assert content['content_type'] == 'page'
316
         assert content['id'] == 16
316
         assert content['id'] == 16
317
         assert content['is_archived'] is True
317
         assert content['is_archived'] is True
318
         assert content['is_deleted'] is False
318
         assert content['is_deleted'] is False
321
         assert content['show_in_ui'] is True
321
         assert content['show_in_ui'] is True
322
         assert content['slug'].startswith('fruit-salad')
322
         assert content['slug'].startswith('fruit-salad')
323
         assert content['status_slug'] == 'open'
323
         assert content['status_slug'] == 'open'
324
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
324
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
325
         assert content['workspace_id'] == 3
325
         assert content['workspace_id'] == 3
326
 
326
 
327
         content = res[3]
327
         content = res[3]
328
-        assert content['content_type_slug'] == 'page'
328
+        assert content['content_type'] == 'page'
329
         assert content['id'] == 17
329
         assert content['id'] == 17
330
         assert content['is_archived'] is False
330
         assert content['is_archived'] is False
331
         assert content['is_deleted'] is True
331
         assert content['is_deleted'] is True
334
         assert content['show_in_ui'] is True
334
         assert content['show_in_ui'] is True
335
         assert content['slug'].startswith('bad-fruit-salad')
335
         assert content['slug'].startswith('bad-fruit-salad')
336
         assert content['status_slug'] == 'open'
336
         assert content['status_slug'] == 'open'
337
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
337
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
338
         assert content['workspace_id'] == 3
338
         assert content['workspace_id'] == 3
339
 
339
 
340
     def test_api__get_workspace_content__ok_200__get_only_active_root_content(self):  # nopep8
340
     def test_api__get_workspace_content__ok_200__get_only_active_root_content(self):  # nopep8
362
         # TODO - G.M - 30-05-2018 - Check this test
362
         # TODO - G.M - 30-05-2018 - Check this test
363
         assert len(res) == 2
363
         assert len(res) == 2
364
         content = res[1]
364
         content = res[1]
365
-        assert content['content_type_slug'] == 'page'
365
+        assert content['content_type'] == 'page'
366
         assert content['id'] == 15
366
         assert content['id'] == 15
367
         assert content['is_archived'] is False
367
         assert content['is_archived'] is False
368
         assert content['is_deleted'] is False
368
         assert content['is_deleted'] is False
371
         assert content['show_in_ui'] is True
371
         assert content['show_in_ui'] is True
372
         assert content['slug'] == 'new-fruit-salad'
372
         assert content['slug'] == 'new-fruit-salad'
373
         assert content['status_slug'] == 'open'
373
         assert content['status_slug'] == 'open'
374
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
374
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
375
         assert content['workspace_id'] == 3
375
         assert content['workspace_id'] == 3
376
 
376
 
377
     def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self):  # nopep8
377
     def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self):  # nopep8
398
         ).json_body   # nopep8
398
         ).json_body   # nopep8
399
         assert len(res) == 1
399
         assert len(res) == 1
400
         content = res[0]
400
         content = res[0]
401
-        assert content['content_type_slug'] == 'page'
401
+        assert content['content_type'] == 'page'
402
         assert content['id'] == 16
402
         assert content['id'] == 16
403
         assert content['is_archived'] is True
403
         assert content['is_archived'] is True
404
         assert content['is_deleted'] is False
404
         assert content['is_deleted'] is False
407
         assert content['show_in_ui'] is True
407
         assert content['show_in_ui'] is True
408
         assert content['slug'].startswith('fruit-salad')
408
         assert content['slug'].startswith('fruit-salad')
409
         assert content['status_slug'] == 'open'
409
         assert content['status_slug'] == 'open'
410
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
410
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
411
         assert content['workspace_id'] == 3
411
         assert content['workspace_id'] == 3
412
 
412
 
413
     def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self):  # nopep8
413
     def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self):  # nopep8
436
 
436
 
437
         assert len(res) == 1
437
         assert len(res) == 1
438
         content = res[0]
438
         content = res[0]
439
-        assert content['content_type_slug'] == 'page'
439
+        assert content['content_type'] == 'page'
440
         assert content['id'] == 17
440
         assert content['id'] == 17
441
         assert content['is_archived'] is False
441
         assert content['is_archived'] is False
442
         assert content['is_deleted'] is True
442
         assert content['is_deleted'] is True
445
         assert content['show_in_ui'] is True
445
         assert content['show_in_ui'] is True
446
         assert content['slug'].startswith('bad-fruit-salad')
446
         assert content['slug'].startswith('bad-fruit-salad')
447
         assert content['status_slug'] == 'open'
447
         assert content['status_slug'] == 'open'
448
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
448
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
449
         assert content['workspace_id'] == 3
449
         assert content['workspace_id'] == 3
450
 
450
 
451
     def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
451
     def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
500
         ).json_body   # nopep8
500
         ).json_body   # nopep8
501
         assert len(res) == 3
501
         assert len(res) == 3
502
         content = res[0]
502
         content = res[0]
503
-        assert content['content_type_slug'] == 'page'
503
+        assert content['content_type'] == 'page'
504
         assert content['id'] == 12
504
         assert content['id'] == 12
505
         assert content['is_archived'] is False
505
         assert content['is_archived'] is False
506
         assert content['is_deleted'] is False
506
         assert content['is_deleted'] is False
509
         assert content['show_in_ui'] is True
509
         assert content['show_in_ui'] is True
510
         assert content['slug'] == 'new-fruit-salad'
510
         assert content['slug'] == 'new-fruit-salad'
511
         assert content['status_slug'] == 'open'
511
         assert content['status_slug'] == 'open'
512
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
512
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
513
         assert content['workspace_id'] == 2
513
         assert content['workspace_id'] == 2
514
 
514
 
515
         content = res[1]
515
         content = res[1]
516
-        assert content['content_type_slug'] == 'page'
516
+        assert content['content_type'] == 'page'
517
         assert content['id'] == 13
517
         assert content['id'] == 13
518
         assert content['is_archived'] is True
518
         assert content['is_archived'] is True
519
         assert content['is_deleted'] is False
519
         assert content['is_deleted'] is False
522
         assert content['show_in_ui'] is True
522
         assert content['show_in_ui'] is True
523
         assert content['slug'].startswith('fruit-salad')
523
         assert content['slug'].startswith('fruit-salad')
524
         assert content['status_slug'] == 'open'
524
         assert content['status_slug'] == 'open'
525
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
525
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
526
         assert content['workspace_id'] == 2
526
         assert content['workspace_id'] == 2
527
 
527
 
528
         content = res[2]
528
         content = res[2]
529
-        assert content['content_type_slug'] == 'page'
529
+        assert content['content_type'] == 'page'
530
         assert content['id'] == 14
530
         assert content['id'] == 14
531
         assert content['is_archived'] is False
531
         assert content['is_archived'] is False
532
         assert content['is_deleted'] is True
532
         assert content['is_deleted'] is True
535
         assert content['show_in_ui'] is True
535
         assert content['show_in_ui'] is True
536
         assert content['slug'].startswith('bad-fruit-salad')
536
         assert content['slug'].startswith('bad-fruit-salad')
537
         assert content['status_slug'] == 'open'
537
         assert content['status_slug'] == 'open'
538
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
538
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
539
         assert content['workspace_id'] == 2
539
         assert content['workspace_id'] == 2
540
 
540
 
541
     def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):  # nopep8
541
     def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):  # nopep8
562
         ).json_body   # nopep8
562
         ).json_body   # nopep8
563
         assert len(res) == 1
563
         assert len(res) == 1
564
         content = res[0]
564
         content = res[0]
565
-        assert content['content_type_slug']
565
+        assert content['content_type']
566
         assert content['id'] == 12
566
         assert content['id'] == 12
567
         assert content['is_archived'] is False
567
         assert content['is_archived'] is False
568
         assert content['is_deleted'] is False
568
         assert content['is_deleted'] is False
571
         assert content['show_in_ui'] is True
571
         assert content['show_in_ui'] is True
572
         assert content['slug'] == 'new-fruit-salad'
572
         assert content['slug'] == 'new-fruit-salad'
573
         assert content['status_slug'] == 'open'
573
         assert content['status_slug'] == 'open'
574
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
574
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
575
         assert content['workspace_id'] == 2
575
         assert content['workspace_id'] == 2
576
 
576
 
577
     def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):  # nopep8
577
     def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):  # nopep8
598
         ).json_body   # nopep8
598
         ).json_body   # nopep8
599
         assert len(res) == 1
599
         assert len(res) == 1
600
         content = res[0]
600
         content = res[0]
601
-        assert content['content_type_slug'] == 'page'
601
+        assert content['content_type'] == 'page'
602
         assert content['id'] == 13
602
         assert content['id'] == 13
603
         assert content['is_archived'] is True
603
         assert content['is_archived'] is True
604
         assert content['is_deleted'] is False
604
         assert content['is_deleted'] is False
607
         assert content['show_in_ui'] is True
607
         assert content['show_in_ui'] is True
608
         assert content['slug'].startswith('fruit-salad')
608
         assert content['slug'].startswith('fruit-salad')
609
         assert content['status_slug'] == 'open'
609
         assert content['status_slug'] == 'open'
610
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
610
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
611
         assert content['workspace_id'] == 2
611
         assert content['workspace_id'] == 2
612
 
612
 
613
     def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):  # nopep8
613
     def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):  # nopep8
635
 
635
 
636
         assert len(res) == 1
636
         assert len(res) == 1
637
         content = res[0]
637
         content = res[0]
638
-        assert content['content_type_slug'] == 'page'
638
+        assert content['content_type'] == 'page'
639
         assert content['id'] == 14
639
         assert content['id'] == 14
640
         assert content['is_archived'] is False
640
         assert content['is_archived'] is False
641
         assert content['is_deleted'] is True
641
         assert content['is_deleted'] is True
644
         assert content['show_in_ui'] is True
644
         assert content['show_in_ui'] is True
645
         assert content['slug'].startswith('bad-fruit-salad')
645
         assert content['slug'].startswith('bad-fruit-salad')
646
         assert content['status_slug'] == 'open'
646
         assert content['status_slug'] == 'open'
647
-        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
647
+        assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'}  # nopep8
648
         assert content['workspace_id'] == 2
648
         assert content['workspace_id'] == 2
649
 
649
 
650
     def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self):  # nopep8
650
     def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self):  # nopep8
741
         )
741
         )
742
         params = {
742
         params = {
743
             'label': 'GenericCreatedContent',
743
             'label': 'GenericCreatedContent',
744
-            'content_type_slug': 'markdownpage',
744
+            'content_type': 'markdownpage',
745
         }
745
         }
746
         res = self.testapp.post_json(
746
         res = self.testapp.post_json(
747
             '/api/v2/workspaces/1/contents',
747
             '/api/v2/workspaces/1/contents',
752
         assert res.json_body
752
         assert res.json_body
753
         assert res.json_body['status_slug'] == 'open'
753
         assert res.json_body['status_slug'] == 'open'
754
         assert res.json_body['id']
754
         assert res.json_body['id']
755
-        assert res.json_body['content_type_slug'] == 'markdownpage'
755
+        assert res.json_body['content_type'] == 'markdownpage'
756
         assert res.json_body['is_archived'] is False
756
         assert res.json_body['is_archived'] is False
757
         assert res.json_body['is_deleted'] is False
757
         assert res.json_body['is_deleted'] is False
758
         assert res.json_body['workspace_id'] == 1
758
         assert res.json_body['workspace_id'] == 1
759
         assert res.json_body['slug'] == 'genericcreatedcontent'
759
         assert res.json_body['slug'] == 'genericcreatedcontent'
760
         assert res.json_body['parent_id'] is None
760
         assert res.json_body['parent_id'] is None
761
         assert res.json_body['show_in_ui'] is True
761
         assert res.json_body['show_in_ui'] is True
762
-        assert res.json_body['sub_content_type_slug']
762
+        assert res.json_body['sub_content_types']
763
         params_active = {
763
         params_active = {
764
             'parent_id': 0,
764
             'parent_id': 0,
765
             'show_archived': 0,
765
             'show_archived': 0,

+ 3 - 3
tracim/views/core_api/schemas.py View File

311
         example='contract for client XXX',
311
         example='contract for client XXX',
312
         description='Title of the content to create'
312
         description='Title of the content to create'
313
     )
313
     )
314
-    content_type_slug = marshmallow.fields.String(
314
+    content_type = marshmallow.fields.String(
315
         example='htmlpage',
315
         example='htmlpage',
316
         validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
316
         validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
317
     )
317
     )
333
         example=19,
333
         example=19,
334
     )
334
     )
335
     label = marshmallow.fields.Str(example='Intervention Report 12')
335
     label = marshmallow.fields.Str(example='Intervention Report 12')
336
-    content_type_slug = marshmallow.fields.Str(
336
+    content_type = marshmallow.fields.Str(
337
         example='htmlpage',
337
         example='htmlpage',
338
         validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
338
         validate=OneOf([content.slug for content in CONTENT_DEFAULT_TYPE]),
339
     )
339
     )
340
-    sub_content_type_slug = marshmallow.fields.List(
340
+    sub_content_types = marshmallow.fields.List(
341
         marshmallow.fields.Str,
341
         marshmallow.fields.Str,
342
         description='list of content types allowed as sub contents. '
342
         description='list of content types allowed as sub contents. '
343
                     'This field is required for folder contents, '
343
                     'This field is required for folder contents, '

+ 1 - 1
tracim/views/core_api/workspace_controller.py View File

145
         )
145
         )
146
         content = api.create(
146
         content = api.create(
147
             label=creation_data.label,
147
             label=creation_data.label,
148
-            content_type=creation_data.content_type_slug,
148
+            content_type=creation_data.content_type,
149
             workspace=request.current_workspace,
149
             workspace=request.current_workspace,
150
         )
150
         )
151
         api.save(content, ActionDescription.CREATION)
151
         api.save(content, ActionDescription.CREATION)