The Content Import Flow
The Content Import Flow
The Wagtail Content Import app provides:
- Pickers - which select and import raw document data
- Parsers - which parse the raw document data into a standard intermediate form
- Mappers - which convert this intermediate form into a final output (typically a Wagtail StreamField)
The typical flow is as follows, for a Page model with ContentImportMixin:
-
The
Createview in the Wagtail Admin provides a button, which calls a picker. -
The picker enables a document to be selected, and makes a POST request to the
Createview with the document data. -
The Wagtail hook for
"before_create_page"in the picker detects the document, and calls a relevant parser. -
The parser's
parse()method converts the raw document data to a list of{'type': type, 'value': value}elements. -
The
create_page_from_importfunction is called, which in turn passes the parsed data to the Page model'screate_from_importmethod (inherited fromContentImportMixin). -
By default, this creates an instance of the Page's
mapper_class, then uses itsmap()method to call a relevant Converter for each{'type': type, 'value': value}element. This returns a StreamField-compatible list of('block_name', block_content)tuples. -
Finally a
Pagemodel instance is created (but not saved) with the document's title, and the content inserted into a field calledbody. -
The
Createview is then rendered with thePagemodel instance bound to the form.