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:

site/settings/base.py

WAGTAIL_MODERATION_ENABLED = False

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:

base/wagtail_hooks.py

@hooks.register('construct_page_action_menu')
def make_publish_default_action(menu_items, request, context):
    for (index, item) in enumerate(menu_items):
        if item.name == 'action-publish':
            menu_items.pop(index)
            menu_items.insert(0, item)
            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.

Related Posts

  • Migrating your Wagtail site to a different database engine
  • Change the Wagtail site domain via a management command
  • Programatically creating redirects in Wagtail
  • Defining custom settings in Wagtail
  • Adding a panel to the admin homepage in Wagtail