diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/js/hallo-plugins/hallo-wagtaillink.js b/wagtail/wagtailadmin/static_src/wagtailadmin/js/hallo-plugins/hallo-wagtaillink.js index d93831f33..dc2fbfd07 100644 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/js/hallo-plugins/hallo-wagtaillink.js +++ b/wagtail/wagtailadmin/static_src/wagtailadmin/js/hallo-plugins/hallo-wagtaillink.js @@ -45,14 +45,13 @@ if (enclosingLink) { href = enclosingLink.getAttribute('href'); - pageId = enclosingLink.getAttribute('data-id'); + parentPageId = enclosingLink.getAttribute('data-parent-id'); linkType = enclosingLink.getAttribute('data-linktype'); urlParams['link_text'] = enclosingLink.innerText; - if (linkType == 'page' && pageId) { - // TODO: Actually show the parent not the page itself. - url = window.chooserUrls.pageChooser + pageId.toString() + '/'; + if (linkType == 'page' && parentPageId) { + url = window.chooserUrls.pageChooser + parentPageId.toString() + '/'; } else if (href.startsWith('mailto:')) { url = window.chooserUrls.emailLinkChooser; href = href.replace('mailto:', ''); @@ -77,6 +76,7 @@ a.setAttribute('href', pageData.url); if (pageData.id) { a.setAttribute('data-id', pageData.id); + a.setAttribute('data-parent-id', pageData.parentId); a.setAttribute('data-linktype', 'page'); } diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/pages/listing/_page_title_choose.html b/wagtail/wagtailadmin/templates/wagtailadmin/pages/listing/_page_title_choose.html index 40e205fdd..aaa86f9b5 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/pages/listing/_page_title_choose.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/pages/listing/_page_title_choose.html @@ -6,7 +6,7 @@ Expects a variable 'page', the page instance.

{% if page.can_choose %} - {{ page.title }} + {{ page.title }} {% else %} {{ page.title }} {% endif %} diff --git a/wagtail/wagtailcore/rich_text.py b/wagtail/wagtailcore/rich_text.py index af0b77839..a3d106c6a 100644 --- a/wagtail/wagtailcore/rich_text.py +++ b/wagtail/wagtailcore/rich_text.py @@ -41,6 +41,9 @@ class PageLinkHandler(object): if for_editor: editor_attrs = 'data-linktype="page" data-id="%d" ' % page.id + parent_page = page.get_parent() + if parent_page: + editor_attrs += 'data-parent-id="%d" ' % parent_page.id else: editor_attrs = '' diff --git a/wagtail/wagtailcore/tests/test_blocks.py b/wagtail/wagtailcore/tests/test_blocks.py index 7178dd909..1e9aabe6b 100644 --- a/wagtail/wagtailcore/tests/test_blocks.py +++ b/wagtail/wagtailcore/tests/test_blocks.py @@ -193,7 +193,7 @@ class TestRichTextBlock(TestCase): self.assertIn( ( '<p>Merry <a data-linktype="page" data-id="4"' - ' href="/events/christmas/">Christmas</a>!</p>' + ' data-parent-id="3" href="/events/christmas/">Christmas</a>!</p>' ), result ) diff --git a/wagtail/wagtailcore/tests/test_rich_text.py b/wagtail/wagtailcore/tests/test_rich_text.py index 4e0a31ad6..9318f6ce7 100644 --- a/wagtail/wagtailcore/tests/test_rich_text.py +++ b/wagtail/wagtailcore/tests/test_rich_text.py @@ -4,6 +4,7 @@ from bs4 import BeautifulSoup from django.test import TestCase from mock import patch +from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.rich_text import ( DbWhitelister, PageLinkHandler, RichText, expand_db_html, extract_attrs) @@ -30,8 +31,20 @@ class TestPageLinkHandler(TestCase): {'id': 1}, True ) - self.assertEqual(result, - '') + self.assertEqual( + result, + '' + ) + + events_page_id = Page.objects.get(url_path='/home/events/').pk + result = PageLinkHandler.expand_db_attributes( + {'id': events_page_id}, + True + ) + self.assertEqual( + result, + '' % events_page_id + ) def test_expand_db_attributes_not_for_editor(self): result = PageLinkHandler.expand_db_attributes(