Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor date getters #109

Merged
merged 3 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions wagtail_wordpress_import/importers/wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,16 @@ def cleaned_first_published_at(self):
return self.clean_date(self.node["wp:post_date_gmt"].strip())

def cleaned_last_published_at(self):
return self.clean_date(self.node["wp:post_modified_gmt"].strip())
try:
return self.clean_date(self.node["wp:post_modified_gmt"].strip())
except KeyError:
return self.cleaned_first_published_at()

def cleaned_latest_revision_created_at(self):
return self.clean_date(self.node["wp:post_modified_gmt"].strip())
try:
return self.clean_date(self.node["wp:post_modified_gmt"].strip())
except KeyError:
return self.cleaned_first_published_at()

def clean_date(self, value):
"""
Expand Down
6 changes: 2 additions & 4 deletions wagtail_wordpress_import/test/fixtures/raw_xml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,8 @@ Nihil hic munitissimus habendi senatus locus, nihil horum?.&lt;/blockquote&gt;</
Nihil hic munitissimus habendi senatus locus, nihil horum?.&lt;/blockquote&gt;</content:encoded>
<excerpt:encoded>Lorem ipsum dolor sit amet</excerpt:encoded>
<wp:post_id>2</wp:post_id>
<wp:post_date>2010-07-13 12:16:46</wp:post_date>
<wp:post_date_gmt>2010-07-13 16:16:46</wp:post_date_gmt>
<wp:post_modified>2010-07-13 12:16:46</wp:post_modified>
<wp:post_modified_gmt>2010-07-13 16:16:46</wp:post_modified_gmt>
<wp:post_date>2010-01-13 12:00:00</wp:post_date>
<wp:post_date_gmt>2010-01-13 16:00:00</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>item-two-title</wp:post_name>
Expand Down
16 changes: 16 additions & 0 deletions wagtail_wordpress_import/test/tests/test_wordpress_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ def test_page_field_values_with_yoast_plugin_disbaled(self):
"This page has a default description",
)

def test_page_field_values_if_no_post_date_modified(self):
page = self.imported_pages.get(title="Item two title")
print(page)
self.assertEqual(str(page.first_published_at.date()), "2010-01-13")
self.assertEqual(str(page.first_published_at.time()), "16:00:00")
self.assertEqual(str(page.last_published_at.date()), "2010-01-13")
self.assertEqual(str(page.last_published_at.time()), "16:00:00")
self.assertEqual(
str(page.latest_revision_created_at.date()),
"2010-01-13",
)
self.assertEqual(
str(page.latest_revision_created_at.time()),
"16:00:00",
)


IMPORTER_RUN_PARAMS_TEST_OVERRIDE_1 = {
"app_for_pages": "example",
Expand Down