Skip to content

Commit

Permalink
Fix add flag link in Wagtail 2.10.
Browse files Browse the repository at this point in the history
Wagtail 2.10 changes the "add_*" variables for the button link that appears in the top right of the header to "action_*". This change supports that while remaining backwards compatible with "add_*".
  • Loading branch information
willbarton committed Aug 18, 2020
1 parent be981f6 commit cbe40ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wagtailflags/templates/wagtailflags/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<li>{{ title }}</li>
</ul>
{% include "wagtailadmin/shared/header.html" with title=title icon=icon %}
{% elif wagtail_header_action %}
{# Wagtail 2.10 changes "add_*" in the shared admin header to "action_*" #}
{% url 'wagtailflags:create_flag' as add_link %}
{% include "wagtailadmin/shared/header.html" with title=title action_icon=icon action_text='Add flag' action_url=add_link %}
{% else %}
{% include "wagtailadmin/shared/header.html" with title=title icon=icon add_text='Add flag' add_link='wagtailflags:create_flag' %}
{% endif %}
4 changes: 4 additions & 0 deletions wagtailflags/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect, render

import wagtail

from flags.models import FlagState
from flags.sources import get_flags
from flags.templatetags.flags_debug import bool_enabled
Expand All @@ -11,6 +13,8 @@
def index(request):
context = {
"flags": sorted(get_flags().values(), key=lambda x: x.name),
# Wagtail 2.10 changes "add_*" in the shared admin header to "action_*"
"wagtail_header_action": wagtail.VERSION >= (2, 10, 0),
}
return render(request, "wagtailflags/index.html", context)

Expand Down

0 comments on commit cbe40ba

Please sign in to comment.