Browse Source

refactoring comment_ids

Guénaël Muller 6 years ago
parent
commit
13e30c8595

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

@@ -555,10 +555,14 @@ class RevisionInContext(object):
555 555
             return None
556 556
 
557 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 563
         comments = self.revision.node.get_comments()
560 564
         # INFO - G.M - 2018-06-177 - Get comments more recent than revision.
561
-        revisions_comments = [
565
+        revision_comments = [
562 566
             comment for comment in comments
563 567
             if comment.created > self.revision.updated
564 568
         ]
@@ -566,19 +570,18 @@ class RevisionInContext(object):
566 570
             # INFO - G.M - 2018-06-177 - if there is a revision more recent
567 571
             # than current remove comments from theses rev (comments older
568 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 575
                 if comment.created < self.next_revision.updated
572 576
             ]
573 577
         sorted_revision_comments = sorted(
574
-            revisions_comments,
578
+            revision_comments,
575 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 586
     # Context-related
584 587
     @property

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

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

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

@@ -423,7 +423,7 @@ class HtmlDocumentContentSchema(ContentSchema):
423 423
 
424 424
 
425 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 427
     revision_id = marshmallow.fields.Int(example=12)
428 428
     created = marshmallow.fields.DateTime(
429 429
         format='%Y-%m-%dT%H:%M:%SZ',