add wordpress migration
This commit is contained in:
@ -10,6 +10,7 @@ from wagtail.admin.panels import FieldPanel
|
||||
from wagtail.fields import RichTextField
|
||||
from wagtail.models import Page
|
||||
from wagtail.search import index
|
||||
from wagtail_wordpress_import.models import WPImportedPageMixin
|
||||
|
||||
from dnscms.fields import CommonStreamField
|
||||
|
||||
@ -36,7 +37,7 @@ class AssociationIndex(Page):
|
||||
search_fields = Page.search_fields
|
||||
|
||||
|
||||
class AssociationPage(Page):
|
||||
class AssociationPage(WPImportedPageMixin, Page):
|
||||
subpage_types = []
|
||||
parent_page_types = ["associations.AssociationIndex"]
|
||||
show_in_menus = False
|
||||
@ -57,7 +58,7 @@ class AssociationPage(Page):
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="+",
|
||||
)
|
||||
website_url = models.URLField()
|
||||
website_url = models.URLField(blank=True)
|
||||
|
||||
content_panels = Page.content_panels + [
|
||||
FieldPanel(
|
||||
@ -83,3 +84,35 @@ class AssociationPage(Page):
|
||||
index.SearchField("excerpt"),
|
||||
index.SearchField("body"),
|
||||
]
|
||||
|
||||
settings_panels = Page.settings_panels + WPImportedPageMixin.wordpress_panels
|
||||
|
||||
def import_wordpress_data(self, data):
|
||||
import html
|
||||
|
||||
# Wagtail page model fields
|
||||
self.title = html.unescape(data["title"])
|
||||
self.slug = data["slug"]
|
||||
self.first_published_at = data["first_published_at"]
|
||||
self.last_published_at = data["last_published_at"]
|
||||
self.latest_revision_created_at = data["latest_revision_created_at"]
|
||||
self.search_description = data["search_description"]
|
||||
|
||||
# debug fields
|
||||
self.wp_post_id = data["wp_post_id"]
|
||||
self.wp_post_type = data["wp_post_type"]
|
||||
self.wp_link = data["wp_link"]
|
||||
self.wp_raw_content = data["wp_raw_content"]
|
||||
self.wp_block_json = data["wp_block_json"]
|
||||
self.wp_processed_content = data["wp_processed_content"]
|
||||
self.wp_normalized_styles = data["wp_normalized_styles"]
|
||||
self.wp_post_meta = data["wp_post_meta"]
|
||||
|
||||
# own model fields
|
||||
self.body = data["body"] or ""
|
||||
|
||||
meta = data["wp_post_meta"]
|
||||
self.association_type = meta.get("neuf_associations_type").lower()
|
||||
self.website_url = meta.get("neuf_associations_homepage") or ""
|
||||
|
||||
self.excerpt = meta.get("excerpt_encoded") or "TODO"
|
||||
|
Reference in New Issue
Block a user