Sfoglia il codice sorgente

refactoring comment_ids

Guénaël Muller 6 anni fa
parent
commit
13e30c8595

+ 13 - 10
tracim/models/context_models.py Vedi File

555
             return None
555
             return None
556
 
556
 
557
     @property
557
     @property
558
-    def comments_ids(self) -> typing.List[int]:
558
+    def comment_ids(self) -> typing.List[int]:
559
+        """
560
+        Get list of ids of all current revision related comments
561
+        :return: list of comments ids
562
+        """
559
         comments = self.revision.node.get_comments()
563
         comments = self.revision.node.get_comments()
560
         # INFO - G.M - 2018-06-177 - Get comments more recent than revision.
564
         # INFO - G.M - 2018-06-177 - Get comments more recent than revision.
561
-        revisions_comments = [
565
+        revision_comments = [
562
             comment for comment in comments
566
             comment for comment in comments
563
             if comment.created > self.revision.updated
567
             if comment.created > self.revision.updated
564
         ]
568
         ]
566
             # INFO - G.M - 2018-06-177 - if there is a revision more recent
570
             # INFO - G.M - 2018-06-177 - if there is a revision more recent
567
             # than current remove comments from theses rev (comments older
571
             # than current remove comments from theses rev (comments older
568
             # than next_revision.)
572
             # than next_revision.)
569
-            revisions_comments = [
570
-                comment for comment in revisions_comments
573
+            revision_comments = [
574
+                comment for comment in revision_comments
571
                 if comment.created < self.next_revision.updated
575
                 if comment.created < self.next_revision.updated
572
             ]
576
             ]
573
         sorted_revision_comments = sorted(
577
         sorted_revision_comments = sorted(
574
-            revisions_comments,
578
+            revision_comments,
575
             key=lambda revision: revision.created
579
             key=lambda revision: revision.created
576
         )
580
         )
577
-        comments_id = [
578
-            comments.content_id
579
-            for comments in sorted_revision_comments
580
-        ]
581
-        return comments_id
581
+        comment_ids = []
582
+        for comment in sorted_revision_comments:
583
+            comment_ids.append(comment.content_id)
584
+        return comment_ids
582
 
585
 
583
     # Context-related
586
     # Context-related
584
     @property
587
     @property

+ 5 - 5
tracim/tests/functional/test_contents.py Vedi File

215
         assert revision['revision_id'] == 6
215
         assert revision['revision_id'] == 6
216
         assert revision['sub_content_types']
216
         assert revision['sub_content_types']
217
         # TODO - G.M - 2018-06-173 - Test with real comments
217
         # TODO - G.M - 2018-06-173 - Test with real comments
218
-        assert revision['comments_ids'] == []
218
+        assert revision['comment_ids'] == []
219
         # TODO - G.M - 2018-06-173 - check date format
219
         # TODO - G.M - 2018-06-173 - check date format
220
         assert revision['created']
220
         assert revision['created']
221
         assert revision['author']
221
         assert revision['author']
236
         assert revision['revision_id'] == 7
236
         assert revision['revision_id'] == 7
237
         assert revision['sub_content_types']
237
         assert revision['sub_content_types']
238
         # TODO - G.M - 2018-06-173 - Test with real comments
238
         # TODO - G.M - 2018-06-173 - Test with real comments
239
-        assert revision['comments_ids'] == []
239
+        assert revision['comment_ids'] == []
240
         # TODO - G.M - 2018-06-173 - check date format
240
         # TODO - G.M - 2018-06-173 - check date format
241
         assert revision['created']
241
         assert revision['created']
242
         assert revision['author']
242
         assert revision['author']
257
         assert revision['revision_id'] == 27
257
         assert revision['revision_id'] == 27
258
         assert revision['sub_content_types']
258
         assert revision['sub_content_types']
259
         # TODO - G.M - 2018-06-173 - Test with real comments
259
         # TODO - G.M - 2018-06-173 - Test with real comments
260
-        assert revision['comments_ids'] == []
260
+        assert revision['comment_ids'] == []
261
         # TODO - G.M - 2018-06-173 - check date format
261
         # TODO - G.M - 2018-06-173 - check date format
262
         assert revision['created']
262
         assert revision['created']
263
         assert revision['author']
263
         assert revision['author']
475
         assert revision['workspace_id'] == 2
475
         assert revision['workspace_id'] == 2
476
         assert revision['revision_id'] == 8
476
         assert revision['revision_id'] == 8
477
         assert revision['sub_content_types']
477
         assert revision['sub_content_types']
478
-        assert revision['comments_ids'] == [18, 19, 20]
478
+        assert revision['comment_ids'] == [18, 19, 20]
479
         # TODO - G.M - 2018-06-173 - check date format
479
         # TODO - G.M - 2018-06-173 - check date format
480
         assert revision['created']
480
         assert revision['created']
481
         assert revision['author']
481
         assert revision['author']
495
         assert revision['workspace_id'] == 2
495
         assert revision['workspace_id'] == 2
496
         assert revision['revision_id'] == 26
496
         assert revision['revision_id'] == 26
497
         assert revision['sub_content_types']
497
         assert revision['sub_content_types']
498
-        assert revision['comments_ids'] == []
498
+        assert revision['comment_ids'] == []
499
         # TODO - G.M - 2018-06-173 - check date format
499
         # TODO - G.M - 2018-06-173 - check date format
500
         assert revision['created']
500
         assert revision['created']
501
         assert revision['author']
501
         assert revision['author']

+ 1 - 1
tracim/views/core_api/schemas.py Vedi File

423
 
423
 
424
 
424
 
425
 class RevisionSchema(ContentDigestSchema):
425
 class RevisionSchema(ContentDigestSchema):
426
-    comments_ids = marshmallow.fields.List(marshmallow.fields.Int(example=4))
426
+    comment_ids = marshmallow.fields.List(marshmallow.fields.Int(example=4))
427
     revision_id = marshmallow.fields.Int(example=12)
427
     revision_id = marshmallow.fields.Int(example=12)
428
     created = marshmallow.fields.DateTime(
428
     created = marshmallow.fields.DateTime(
429
         format='%Y-%m-%dT%H:%M:%SZ',
429
         format='%Y-%m-%dT%H:%M:%SZ',