mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-03 21:14:46 +00:00
Track parent page for internal links in rich text - fixes #2639
This commit is contained in:
parent
978cef5218
commit
aacb1116db
7 changed files with 26 additions and 8 deletions
|
|
@ -16,6 +16,7 @@ Changelog
|
|||
* Fix: Rich text editor is no longer broken in InlinePanels (Matt Westcott, Yann Fouillat)
|
||||
* Fix: Rich text editor is no longer broken in settings (Matt Westcott)
|
||||
* Fix: Link tooltip now shows correct urls for newly inserted document links (Matt Westcott)
|
||||
* Fix: Now page chooser (in a rich text editor) opens up at the link's parent page, rather than at the page itself (Matt Westcott)
|
||||
|
||||
|
||||
1.5 (31.05.2016)
|
||||
|
|
|
|||
|
|
@ -19,3 +19,4 @@ Bug fixes
|
|||
* Rich text editor is no longer broken in InlinePanels (Matt Westcott, Yann Fouillat)
|
||||
* Rich text editor is no longer broken in settings (Matt Westcott)
|
||||
* Link tooltip now shows correct urls for newly inserted document links (Matt Westcott)
|
||||
* Now page chooser (in a rich text editor) opens up at the link's parent page, rather than at the page itself (Matt Westcott)
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ Expects a variable 'page', the page instance.
|
|||
|
||||
<h2>
|
||||
{% if page.can_choose %}
|
||||
<a class="choose-page" href="#{{ page.id }}" data-id="{{ page.id }}" data-title="{{ page.title }}" data-url="{{ page.url }}" data-edit-url="{% url 'wagtailadmin_pages:edit' page.id %}">{{ page.title }}</a>
|
||||
<a class="choose-page" href="#{{ page.id }}" data-id="{{ page.id }}" data-title="{{ page.title }}" data-url="{{ page.url }}" data-parent-id="{{ page.get_parent.id }}" data-edit-url="{% url 'wagtailadmin_pages:edit' page.id %}">{{ page.title }}</a>
|
||||
{% else %}
|
||||
{{ page.title }}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -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 = ''
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
'<a data-linktype="page" data-id="1" href="None">')
|
||||
self.assertEqual(
|
||||
result,
|
||||
'<a data-linktype="page" data-id="1" href="None">'
|
||||
)
|
||||
|
||||
events_page_id = Page.objects.get(url_path='/home/events/').pk
|
||||
result = PageLinkHandler.expand_db_attributes(
|
||||
{'id': events_page_id},
|
||||
True
|
||||
)
|
||||
self.assertEqual(
|
||||
result,
|
||||
'<a data-linktype="page" data-id="%d" data-parent-id="2" href="/events/">' % events_page_id
|
||||
)
|
||||
|
||||
def test_expand_db_attributes_not_for_editor(self):
|
||||
result = PageLinkHandler.expand_db_attributes(
|
||||
|
|
|
|||
Loading…
Reference in a new issue