Repository: django-cms/django-cms

Issue:
Fix #985, typos in comments
Fixed #985 and added a test

I think it would be safer to also add a filter on the site, at least for root nodes (non-root nodes rely on the parent).

Also, I think there's something wrong with this test (in Page._publisher_save_public):

```
            not (self.level > 0 and self.parent.publisher_public == self.old_public.parent)
```

This is always true for root nodes, so the branch for moved nodes is always taken. I didn't touch this, though, because the final result seems to be the same if a root node is modified but not moved.

Finally, why not include filters on node status (and site) as defaults in get_*_filtered_sibling?
After all we're looking for the next/previous sibling among nodes of the same kind (draft or public).
I can't think of a case where we might need to find a sibling for a public node including drafts (or nodes from a different site).



Discussion:
thanks for the pull request. For the future please do not mix cleanup (comments/codestyle) and actual fixes in a single pull request, since that just makes it a lot harder for us to review. Instead, please send two pull requests (one with the fix, one with cleanup).

Didn't you say in #985 that get_previous_filtered_siblings should also filter by site?

I did, but I couldn't write a failing test, so I just submitted this.
I'm still working on the site part.

If you hop on IRC (#django-cms on freenode) I might be able to help you with that test

the test you added doesn't actually seem to test what this issue is about...

Why not?
I opened #985 because the home page was losing its status when the user updated it, which is exactly what PagesTestCase.test_public_home_page_replaced tests.
Probably it's too specific, and I agree that other test cases are missing (e.g. multi-site, non-root nodes with unpublished siblings, ...). I hope I'll be able to include them in the next submission.

I've written a test and fix for it now, nvm


Resolving patch:
diff --git a/cms/models/pagemodel.py b/cms/models/pagemodel.py
--- a/cms/models/pagemodel.py
+++ b/cms/models/pagemodel.py
@@ -959,7 +959,16 @@ def get_previous_filtered_sibling(self, **filters):
                 '%s__lt' % opts.right_attr: getattr(self, opts.left_attr),
             })
             order_by = '-%s' % opts.right_attr
-
+        
+        # publisher stuff
+        filters.update({
+            'publisher_is_draft': self.publisher_is_draft
+        })
+        # multisite
+        filters.update({
+            'site__id': self.site_id
+        })
+        
         sibling = None
         try:
             sibling = self._tree_manager.filter(**filters).order_by(order_by)[0]


Test patch:
diff --git a/cms/tests/page.py b/cms/tests/page.py
--- a/cms/tests/page.py
+++ b/cms/tests/page.py
@@ -532,3 +532,27 @@ def test_get_page_from_request_fakeadmin_nopage(self):
         request = self.get_request('/admin/')
         page = get_page_from_request(request)
         self.assertEqual(page, None)
+
+class PreviousFilteredSiblingsTests(CMSTestCase):
+    def test_with_publisher(self):
+        home = create_page('home', 'nav_playground.html', 'en', published=True)
+        home.publish()
+        other = create_page('other', 'nav_playground.html', 'en', published=True)
+        other.publish()
+        other = Page.objects.get(pk=other.pk)
+        home = Page.objects.get(pk=home.pk)
+        self.assertEqual(other.get_previous_filtered_sibling(), home)
+        self.assertEqual(home.get_previous_filtered_sibling(), None)
+        
+    def test_multisite(self):
+        firstsite = Site.objects.create(name='first', domain='first.com')
+        secondsite = Site.objects.create(name='second', domain='second.com')
+        home = create_page('home', 'nav_playground.html', 'en', published=True, site=firstsite)
+        home.publish()
+        other = create_page('other', 'nav_playground.html', 'en', published=True, site=secondsite)
+        other.publish()
+        other = Page.objects.get(pk=other.pk)
+        home = Page.objects.get(pk=home.pk)
+        self.assertEqual(other.get_previous_filtered_sibling(), None)
+        self.assertEqual(home.get_previous_filtered_sibling(), None)
+