mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-21 13:31:54 +00:00
Fix queryset ordering and add a test to confirm ordering matches expectation in all setups
This commit is contained in:
parent
be534ee535
commit
34579c3776
5 changed files with 51 additions and 1 deletions
|
|
@ -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)
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
|||
16
docs/releases/2.1.1.rst
Normal file
16
docs/releases/2.1.1.rst
Normal file
|
|
@ -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)
|
||||
|
|
@ -5,6 +5,7 @@ Release notes
|
|||
:maxdepth: 1
|
||||
|
||||
upgrading
|
||||
2.1.1
|
||||
2.1
|
||||
2.0.1
|
||||
2.0
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue