Skip to content

Commit

Permalink
Add <p> tags to imports that dont have them
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaoming committed Dec 19, 2016
1 parent 562b4a4 commit 500db59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion blog/management/commands/wordpress_to_wagtail.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from base64 import b64encode

from datetime import datetime
try:
import html
Expand Down Expand Up @@ -339,9 +340,14 @@ def create_blog_pages(self, posts, blog_index, *args, **options):
description = post.get('description')
if description:
description = self.convert_html_entities(description)
body = linebreaks(post.get('content'))

body = post.get('content')
if not "<p>" in body:
body = linebreaks(body)

# get image info from content and create image objects
body = self.create_images_from_urls_in_content(body)

# author/user data
author = post.get('author')
user = self.create_user(author)
Expand Down
4 changes: 4 additions & 0 deletions blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def test_import_xml(self):
self.assertEqual(child_category.slug, "cheat-sheets")
self.assertEqual(parent_category.slug, "marketing-2")

# Assert that <p> tags were added to the post that didn't contain them
page = BlogPage.objects.filter(slug='asa-releases-2013-economic-analysis-of-staffing-industry-trends').get()
self.assertEqual(page.body, "<p>The American Staffing Association has released its 2013 economic analysis,\"Navigating the 1% Economy.\" Written by ASA chief operating officer Steven P. Berchem, CSP, the report takes an in-depth look at recent staffing employment trends and what these suggest about the current economic environment and future labor market conditions.</p>")


def test_import_xml_comments(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion example_export.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Sorry that not work]]></wp:comment_content>
<dc:creator>[email protected]</dc:creator>
<guid isPermaLink="false">http://blog.blog.com/?post_type=articles&#038;p=521</guid>
<description></description>
<content:encoded><![CDATA[<p>The American Staffing Association has released its 2013 economic analysis,"Navigating the 1% Economy." Written by ASA chief operating officer Steven P. Berchem, CSP, the report takes an in-depth look at recent staffing employment trends and what these suggest about the current economic environment and future labor market conditions.</p>]]></content:encoded>
<content:encoded><![CDATA[The American Staffing Association has released its 2013 economic analysis,"Navigating the 1% Economy." Written by ASA chief operating officer Steven P. Berchem, CSP, the report takes an in-depth look at recent staffing employment trends and what these suggest about the current economic environment and future labor market conditions.]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>521</wp:post_id>
<wp:post_date>2013-11-19 17:27:33</wp:post_date>
Expand Down

0 comments on commit 500db59

Please sign in to comment.