fix: page url is None for headless sites

pull/9984/head
Darrel O'Pry 2023-01-29 20:40:30 -05:00
rodzic 857b6d6519
commit 82f39f4aed
2 zmienionych plików z 16 dodań i 4 usunięć

Wyświetl plik

@ -2103,7 +2103,15 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
"wagtail_serve", args=(self.url_path[len(root_path) :],)
)
except NoReverseMatch:
return (site_id, None, None)
"""
wagtail_serve is not mounted, this is most likely a headless Wagtail,
use the path rather than processsing through wagtail_serve -1 maintains
the leading slash needed to create a root relative URL Path.
TODO: review whether additional work is needed to support Multisite and i18n
url generation in headless Wagtail.
"""
page_path = self.url_path[len(root_path) - 1 :]
# Remove the trailing slash from the URL reverse generates if
# WAGTAIL_APPEND_SLASH is False and we're not trying to serve

Wyświetl plik

@ -432,16 +432,20 @@ class TestRouting(TestCase):
# for now headless installations will return the url relative to the default site.
# additional work probably needs to be done to enable multisite in headless modes
# without this page links in richtext blocks have href=None
self.assertEqual(homepage.get_url_parts(), (default_site.id, "http://localhost", "/"))
self.assertEqual(
homepage.get_url_parts(), (default_site.id, "http://localhost", "/")
)
self.assertEqual(homepage.full_url, "http://localhost/")
self.assertEqual(homepage.url, "/")
events_page = Page.objects.get(url_path="/home/events/")
self.assertEqual(events_page.get_url_parts(), (default_site.id, "http://localhost", "/events/"))
self.assertEqual(
events_page.get_url_parts(),
(default_site.id, "http://localhost", "/events/"),
)
self.assertEqual(events_page.full_url, "http://localhost/events/")
self.assertEqual(events_page.url, "/events/")
def test_request_routing(self):
homepage = Page.objects.get(url_path="/home/")
christmas_page = EventPage.objects.get(url_path="/home/events/christmas/")