kopia lustrzana https://github.com/wagtail/wagtail
Merge 82f39f4aed
into 7c6187f06c
commit
a4a03708a1
|
@ -2086,7 +2086,15 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
|
||||||
"wagtail_serve", args=(self.url_path[len(root_path) :],)
|
"wagtail_serve", args=(self.url_path[len(root_path) :],)
|
||||||
)
|
)
|
||||||
except NoReverseMatch:
|
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
|
# Remove the trailing slash from the URL reverse generates if
|
||||||
# WAGTAIL_APPEND_SLASH is False and we're not trying to serve
|
# WAGTAIL_APPEND_SLASH is False and we're not trying to serve
|
||||||
|
|
|
@ -473,11 +473,22 @@ class TestRouting(TestCase):
|
||||||
default_site = Site.objects.get(is_default_site=True)
|
default_site = Site.objects.get(is_default_site=True)
|
||||||
homepage = Page.objects.get(url_path="/home/")
|
homepage = Page.objects.get(url_path="/home/")
|
||||||
|
|
||||||
# The page should not be routable because wagtail_serve is not registered
|
# for now headless installations will return the url relative to the default site.
|
||||||
# However it is still associated with a site
|
# additional work probably needs to be done to enable multisite in headless modes
|
||||||
self.assertEqual(homepage.get_url_parts(), (default_site.id, None, None))
|
# without this page links in richtext blocks have href=None
|
||||||
self.assertIsNone(homepage.full_url)
|
self.assertEqual(
|
||||||
self.assertIsNone(homepage.url)
|
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.full_url, "http://localhost/events/")
|
||||||
|
self.assertEqual(events_page.url, "/events/")
|
||||||
|
|
||||||
def test_request_routing(self):
|
def test_request_routing(self):
|
||||||
homepage = Page.objects.get(url_path="/home/")
|
homepage = Page.objects.get(url_path="/home/")
|
||||||
|
|
|
@ -23,6 +23,13 @@ class TestPageLinktypeHandler(TestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(result, '<a href="/events/christmas/">')
|
self.assertEqual(result, '<a href="/events/christmas/">')
|
||||||
|
|
||||||
|
@override_settings(ROOT_URLCONF="wagtail.test.headless_urls")
|
||||||
|
def test_expand_db_attributes_headless(self):
|
||||||
|
result = PageLinkHandler.expand_db_attributes(
|
||||||
|
{"id": Page.objects.get(url_path="/home/events/christmas/").id}
|
||||||
|
)
|
||||||
|
self.assertEqual(result, '<a href="/events/christmas/">')
|
||||||
|
|
||||||
def test_expand_db_attributes_page_does_not_exist(self):
|
def test_expand_db_attributes_page_does_not_exist(self):
|
||||||
result = PageLinkHandler.expand_db_attributes({"id": 0})
|
result = PageLinkHandler.expand_db_attributes({"id": 0})
|
||||||
self.assertEqual(result, "<a>")
|
self.assertEqual(result, "<a>")
|
||||||
|
|
Ładowanie…
Reference in New Issue