Skip to content

Commit

Permalink
Look for embedtypes in RichText
Browse files Browse the repository at this point in the history
  • Loading branch information
KalobTaulien authored and gasman committed Mar 26, 2020
1 parent 19e940d commit f813c08
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
~~~~~~~~~~~~~~~~~~

* Fix error when exporting empty non-required ChooserBlocks (Kalob Taulinen, Jacob Topp-Mugglestone)
* Fix handling of embeds in rich text (Kalob Taulinen, Jacob Topp-Mugglestone)
* Ensure that file URLs are always absolute by falling back on BASE_URL when MEDIA_URL is local (Kalob Taulinen)


Expand Down
23 changes: 23 additions & 0 deletions tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ def test_rich_text_with_dead_page_link(self):
for model, id, uid in data['mappings']
))

def test_rich_text_with_image_embed(self):
with open(os.path.join(FIXTURES_DIR, 'wagtail.jpg'), 'rb') as f:
image = Image.objects.create(
title="Wagtail",
file=ImageFile(f, name='wagtail.jpg')
)

body = '<p>Here is an image</p><embed embedtype="image" id="%d" alt="A wagtail" format="left" />' % image.pk
page = PageWithRichText(title="The cake is a lie.", body=body)

parent_page = Page.objects.get(url_path='/home/existing-child-page/')
parent_page.add_child(instance=page)

response = self.get(page.id)

self.assertEqual(response.status_code, 200)
data = json.loads(response.content)

self.assertTrue(any(
model == 'wagtailimages.image' and pk == image.pk
for model, pk, uid in data['mappings']
))

def test_streamfield_with_page_links(self):
# Check that page links in a complex nested StreamField - with StreamBlock, StructBlock, and ListBlock -
# are all picked up in mappings
Expand Down
2 changes: 1 addition & 1 deletion wagtail_transfer/richtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ def get_reference_handler():
link_handlers = features.get_link_types()
REFERENCE_HANDLER = MultiTypeRichTextReferenceHandler([
RichTextReferenceHandler(link_handlers, FIND_A_TAG, 'linktype'),
RichTextReferenceHandler(embed_handlers, FIND_EMBED_TAG, 'embed')
RichTextReferenceHandler(embed_handlers, FIND_EMBED_TAG, 'embedtype')
])
return REFERENCE_HANDLER

0 comments on commit f813c08

Please sign in to comment.