#django #python #wagtail

I recently started playing around with the Wagtail CMS. I'm really impressed and I'm currently mgirating my blog (again) from a plain Django app to a Wagtail app.

Since I'm the only one editing content, the first thing I changed was to disable the moderation feature. You can do this by altering the settings of your Wagtail install. In my case, I added the following statement to the base settings file:



The next thing I wanted to do was to make the default action when creating a new page the "Publish" action instead of "Save Draft". This can also be done, but in a slightly different way. You can do this by using the hooks feature of Wagtail.

In any of your apps which you installed in your Wagtail install, you can add a file called wagtail_hooks.py. In my setups, I tend to create an app called base in which I can define all basic page models etc. That's the perfect place for putting this hook:


2def make_publish_default_action(menu_items, request, context):
3    for (index, item) in enumerate(menu_items):
4        if item.name == 'action-publish':
5            menu_items.pop(index)
6            menu_items.insert(0, item)
7            break

The hook you should be using is called construct_page_action_menu and is called every time the admin UI needs to build the page action menu. All you need to do in there is to move the publish action to the first place.

What I did notice when playing around with hooks is that sometimes, you might need to restart the server to get it to work.