-
Notifications
You must be signed in to change notification settings - Fork 3
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
Provide upgrade path to Wagtail 2.0 #64
Comments
Upgrade considerationsWhile Draftail was merged into Wagtail 2.0, it isn't a like for like integration. It might get a bit awkward as some steps need to be completed together (e.g. the data needs to be migrated in order to test the new configuration changes but the configuration cannot be tested/tweaked until the data is migrated) which might require some trial and error. It would probably be a good idea to first upgrade WagtailDraftail to use Draftail 0.17 (the same as Wagtail 2.0) before upgrading Wagtail in order to keep Draftail and Wagtail upgrade issue separate. Be aware though that the Draftail API changed a fair bit, especially around how sources (i.e. modals) and decorators (i.e. entities) are created in Draftail (around v0.11). You can have a look at WagtailModelChoosers updates to use React 16 to match Wagtail, hook with Wagtail 1.12 rich text features (although the commit here is in relation to Wagtail 2.0) and fix compatibility with Draftail 0.17 (although it's not fully working, see corresponding discussion in case a fix is found). |
Hey @dgkohn, thanks for that. There should be some sub sections as well (data needs to be migrated, etc). Would you mind sharing this as well? |
Glad to help @loicteixeira ! Is this the one you're talking? Upgrade considerationsA complete rework of the StreamField UI is underway (see wagtail/wagtail#4473) and while the API should remain backward compatibile, this will be something to watch closely. Customisations from /wagtailaddons/wagtailfacelift/ will most certainly need to be updated (it contains more than just StreamField style fixes so it might not be possible to remove it altogether) as the main purpose was to allow deep block nesting to work well but the new UI should handle this much better. |
Unfortunately no. It is related to draftail and should be right under the upgrade consideration that you pasted in your first comment. It would explain the different steps (e.g. "convert plugins to rich text features" or "migrate data from JSON format to new format") in details (IIRC there should be about 4). Maybe it's on an unmerged PR? Otherwise you might want to have a look at my latest commits to dig this up before it's too late because you'll definitely need it when upgrading the project. Thanks for the help though. I should have copied this here before leaving. |
Nice @loicteixeira ! I'll take a look and then I'll update my last comment 👍 |
Configuring rich text featuresRich text features are now made available via the
Migrating the dataData isn't saved as JSON anymore and will need to be migrated. When using Draftail, it consistently converts between the database format and the content state (JSON) format. Therefore the migration has to recreate what the editor does upon save:
This will have to be executed within a migration. While it shouldn't be too much trouble to build a list of all Control rendering of front-end componentsBecause the content isn't saved as JSON anymore but in some pseudo XML/HTML, it isn't possible to control the rendering of front-end components with decorators. However it should be possible to convert the raw data back to JSON and then render it as we use to do. This would normally have huge performance implications but because the site is statically rendered, this shouldn't be an issue. There's two way to go about it, either create a custom In any case, the same conversion process will have to happen (either in the filter function or in the Note that such request has come up and a built-in solution might exist by then. 1. Converting the data back to JSONImportant: It assumes that the various fields and blocks have been converted to use the new If the field widget is available and initialised at this point in time, it might simply be a matter of calling
2. Render the JSON to HTML with our custom configRecreate what WagtailDraftail's
|
sorry for delay @loicteixeira |
No worries. Thank you for sharing it. Hopefuly that might help someone out there :) |
Thanks @mojeto and sorry @loicteixeira I've missed this one. |
@loicteixeira is there any tool or example how to migrate |
What you want is most likely Wagtail's own Within the normal lifecycle of rich text in Wagtail, it would be configured based on the enabled features of the rich text editor for which content is saved. For a migration, you will need to decide which features to enable (and how to configure them) based on the content to migrate. Wagtail's built-in features are probably a good start. |
Exactly. WagtailDraftail used to save the ContentState JSON to the database, would use it directly for the editor and only convert it to HTML when needed for the front-end. With Wagtail 2.0 on the other hand, the ContentState only exists for the editor. It will be converted to the "DB Format" upon save then used with limited modifications for the front-end (and converted back to ContentState whenever you use the editor again). With that in mind, by using ContentstateConverter#to_database_format once on the existing data, it should then be compatible with the Wagtail 2.0 way. There are 2 things to consider though:
|
thanks @thibaudcolas and @loicteixeira I'm in process of this migration for one of our project. Migrate |
Streamfield migrations have always been a pain point 😞 There is an example in the documentation, there are some more in Springload internal Wiki (under Wagtail Tips) although I think I never got to fully write the recursive one (but the idea on how to pack/unpack StreamField safely is there). You might be able to find some hints in the PR for listing objects uses as it goes through StreamFields, although I suspect it does it in the database. Lastly there might be a example in the migrations of the project I think you are migrating as I had to replace a block once. You might need to play with the history as the migrations would have been squashed since then. |
Thanks @loicteixeira , https://github.com/BertrandBordage/wagtail/blob/93e5e32762f9eae08473fae666e692a87a6e01d6/wagtail/core/collectors.py helped. I'm working on tools to help with this migration process https://gist.github.com/mojeto/eaad9f10236044bd9df9fb3bef5e1fda After it's all finished and tested I may create a python package for it to help others with migration. The reason I'm thinking about separate package is so I don't have to make |
I struggle a bit with converting extra draftail features into new configuration.
It creates a simple
it produces Do I have to create a completely new entity just for a paragraph tag with class attribute? What Am I missing here? |
The This would be the easiest solution, but before I though of it, I had written about differents solutions which I'll leave further down just in case the above doesn't work or if you need even more control. It is no longer possible to control the output on the front-end side with Wagtail 2.0 the same way we did with WagtailDraftail (see wagtail/wagtail#4223), mostly because the data isn't saved as JSON anymore but is already in HTML form. With Wagtail 2.0, the front-end HTML isn't much different from the DB HTML. It goes through a few hoops (e.g. to replace links IDs with their actual URLs) but that's pretty much it and it's mostly Regexp based instead of using DraftJSExporter. Here are a few ideas on how to achieve full control over the front-end presentation: Still use DraftJSExporter: Create a custom rich text tag/node which will take the DB HTML and turn it back to JSON ContentState (basically running the Work with Wagtail's Rewriters: Create a custom rich text tag/node which will use a overriden |
Thanks for all the options and explanation @loicteixeira I play with it for some time now to find the best solution to our draftail components I'm trying to migrate. I found
but it requires wagtail/wagtail#4527 to be resolved. |
This migration is becoming really painful. I'll need to find a way to remap wagtaildraftail I understand the draftail content state json is converted to db html string for backward compatibility reason. As you @loicteixeira mentioned earlier with wagtaildraftail rich text we have possibilities to control wagtail admin part of feature and final front-end user html part of feature. The inner content state in json contains all the state data feature needs and it isn't in developer's main interest. Now we need to convert all our features data to db html string and back to json - and that is a lot of work. The db html can't be fron-end user html as it's main responsibility is to keep all the data feature needs (including the data for feature internal use and not to be displayed to end user). The feature db html code has to be unique enough so it can be easily parsed back to proper draftail feature also. All that means we have to create json -> db html converter and back to replicate work that was done for us by content state json. In addition we have to create converters for the db html -> front end user html for advance features and to remove internal feature data. All of that has to be done to keep the same functionality we already have. It doesn't help that We at Springload seriously consider repurposing this package to provide us |
Now that it is merged into Wagtail 2.0, there's little point in updating this package compatibility. Instead, provide an upgrade path since since are handled a bit differently.
The text was updated successfully, but these errors were encountered: