diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 286231032..813458d66 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,12 @@ Changelog ========= +2.1.1 (xx.xx.xxxx) - IN DEVELOPMENT +~~~~~~~~~~~~~~~~~~ + + * Fix: Site.get_site_root_paths() preferring other sites over the default when some sites share the same root_page (Andy Babic) + + 2.1 (22.05.2018) ~~~~~~~~~~~~~~~~ diff --git a/docs/releases/2.1.1.rst b/docs/releases/2.1.1.rst new file mode 100644 index 000000000..60d15310f --- /dev/null +++ b/docs/releases/2.1.1.rst @@ -0,0 +1,16 @@ +============================================ +Wagtail 2.1.1 release notes - IN DEVELOPMENT +============================================ + +.. contents:: + :local: + :depth: 1 + + +What's new +========== + +Bug fixes +~~~~~~~~~ + + * Fix ``Site.get_site_root_paths()`` preferring other sites over the default when some sites share the same root_page (Andy Babic) diff --git a/docs/releases/index.rst b/docs/releases/index.rst index fd771d0bd..015f25ce7 100644 --- a/docs/releases/index.rst +++ b/docs/releases/index.rst @@ -5,6 +5,7 @@ Release notes :maxdepth: 1 upgrading + 2.1.1 2.1 2.0.1 2.0 diff --git a/wagtail/core/models.py b/wagtail/core/models.py index 81f4d06c7..bba1473ed 100644 --- a/wagtail/core/models.py +++ b/wagtail/core/models.py @@ -161,7 +161,7 @@ class Site(models.Model): result = [ (site.id, site.root_page.url_path, site.root_url) for site in Site.objects.select_related('root_page').order_by( - '-root_page__url_path', 'is_default_site', 'hostname') + '-root_page__url_path', '-is_default_site', 'hostname') ] cache.set('wagtail_site_root_paths', result, 3600) diff --git a/wagtail/core/tests/test_sites.py b/wagtail/core/tests/test_sites.py index 860c251ea..f7c0ef2b6 100644 --- a/wagtail/core/tests/test_sites.py +++ b/wagtail/core/tests/test_sites.py @@ -122,3 +122,30 @@ class TestDefaultSite(TestCase): with self.assertRaises(Site.MultipleObjectsReturned): # If there already are multiple default sites, you're in trouble site.clean_fields() + + +class TestGetSiteRootPaths(TestCase): + + def setUp(self): + self.default_site = Site.objects.get() + self.abc_site = Site.objects.create( + hostname='abc.com', root_page=self.default_site.root_page + ) + self.def_site = Site.objects.create( + hostname='def.com', root_page=self.default_site.root_page + ) + + # Changing the hostname to show that being the default site takes + # promotes a site over the alphabetical ordering of hostname + self.default_site.hostname = 'xyz.com' + self.default_site.save() + + def test_result_order_when_multiple_sites_share_the_same_root_page(self): + result = Site.get_site_root_paths() + + # An entry for the default site should come first + self.assertEqual(result[0][0], self.default_site.id) + + # Followed by entries for others in 'host' alphabetical order + self.assertEqual(result[1][0], self.abc_site.id) + self.assertEqual(result[2][0], self.def_site.id)