Browse Source

[#601] fix 'created' field and comments_ids fields for revisions

Guénaël Muller 6 years ago
parent
commit
aa7730cf75
2 changed files with 46 additions and 6 deletions
  1. 45 3
      tracim/models/context_models.py
  2. 1 3
      tracim/tests/functional/test_contents.py

+ 45 - 3
tracim/models/context_models.py View File

@@ -507,7 +507,7 @@ class RevisionInContext(object):
507 507
 
508 508
     @property
509 509
     def created(self):
510
-        return self.revision.created
510
+        return self.updated
511 511
 
512 512
     @property
513 513
     def modified(self):
@@ -518,9 +518,51 @@ class RevisionInContext(object):
518 518
         return self.revision.updated
519 519
 
520 520
     @property
521
+    def next_revision(self):
522
+        next_revision = None
523
+        revisions = self.revision.node.revisions
524
+        # INFO - G.M - 2018-06-177 - Get revisions more recent that
525
+        # current one
526
+        next_revisions = [
527
+            revision for revision in revisions
528
+            if revision.revision_id > self.revision.revision_id
529
+        ]
530
+        if next_revisions:
531
+            # INFO - G.M - 2018-06-177 -sort revisions by date
532
+            sorted_next_revisions = sorted(
533
+                next_revisions,
534
+                key=lambda revision: revision.updated
535
+            )
536
+            # INFO - G.M - 2018-06-177 - return only next revision
537
+            return sorted_next_revisions[0]
538
+        else:
539
+            return None
540
+
541
+    @property
521 542
     def comments_ids(self):
522
-        # TODO - G.M - 2018-06-173 - Return comments related to this revision
523
-        return []
543
+        comments = self.revision.node.get_comments()
544
+        # INFO - G.M - 2018-06-177 - Get comments more recent than revision.
545
+        revisions_comments = [
546
+            comment for comment in comments
547
+            if comment.created > self.revision.updated
548
+        ]
549
+        if self.next_revision:
550
+            # INFO - G.M - 2018-06-177 - if there is a revision more recent
551
+            # than current remove comments from theses rev (comments older
552
+            # than next_revision.)
553
+            revisions_comments = [
554
+                comment for comment in revisions_comments
555
+                if comment.created < self.next_revision.updated
556
+            ]
557
+        sorted_revision_comments = sorted(
558
+            revisions_comments,
559
+            key=lambda revision: revision.created
560
+        )
561
+        comments_id = [
562
+            comments.content_id
563
+            for comments in sorted_revision_comments
564
+        ]
565
+        return comments_id
524 566
 
525 567
     # Context-related
526 568
     @property

+ 1 - 3
tracim/tests/functional/test_contents.py View File

@@ -432,8 +432,7 @@ class TestThreads(FunctionalTest):
432 432
         assert revision['workspace_id'] == 2
433 433
         assert revision['revision_id'] == 8
434 434
         assert revision['sub_content_types']
435
-        # TODO - G.M - 2018-06-173 - Test with real comments
436
-        assert revision['comments_ids'] == []
435
+        assert revision['comments_ids'] == [18, 19, 20]
437 436
         # TODO - G.M - 2018-06-173 - check date format
438 437
         assert revision['created']
439 438
         assert revision['author']
@@ -453,7 +452,6 @@ class TestThreads(FunctionalTest):
453 452
         assert revision['workspace_id'] == 2
454 453
         assert revision['revision_id'] == 26
455 454
         assert revision['sub_content_types']
456
-        # TODO - G.M - 2018-06-173 - Test with real comments
457 455
         assert revision['comments_ids'] == []
458 456
         # TODO - G.M - 2018-06-173 - check date format
459 457
         assert revision['created']