Wagtail 4 changes
This commit is contained in:
@@ -20,6 +20,10 @@
|
|||||||
</title>
|
</title>
|
||||||
<meta name="description" content="" />
|
<meta name="description" content="" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
{% comment %} Required in Wagtail v4+ for page previews {% endcomment %}
|
||||||
|
{% if request.in_preview_panel %}
|
||||||
|
<base target="_blank">
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{# Global stylesheets #}
|
{# Global stylesheets #}
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'css/sandbox.css' %}">
|
<link rel="stylesheet" type="text/css" href="{% static 'css/sandbox.css' %}">
|
||||||
|
4
setup.py
4
setup.py
@@ -2,9 +2,9 @@ import re
|
|||||||
from setuptools import find_packages, setup
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
install_requires = [
|
install_requires = [
|
||||||
'wagtail>=2.15,<4.0',
|
'wagtail>=2.15,<4.1',
|
||||||
'user-agents>=1.1.0',
|
'user-agents>=1.1.0',
|
||||||
'wagtailfontawesome>=1.1.3',
|
'wagtail-font-awesome-svg>=0.0.3',
|
||||||
'pycountry',
|
'pycountry',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@@ -133,8 +133,16 @@ def dont_show_variant(parent_page, pages, request):
|
|||||||
return utils.exclude_variants(pages)
|
return utils.exclude_variants(pages)
|
||||||
|
|
||||||
|
|
||||||
|
if WAGTAIL_VERSION >= (4, 0):
|
||||||
|
# removed in Wagtail 4.0
|
||||||
|
# https://docs.wagtail.org/en/stable/releases/4.0.html#is-parent-removed-from-page-button-hooks
|
||||||
|
is_parent = {}
|
||||||
|
else:
|
||||||
|
is_parent = {"is_parent": False}
|
||||||
|
|
||||||
|
|
||||||
@hooks.register("register_page_listing_buttons")
|
@hooks.register("register_page_listing_buttons")
|
||||||
def page_listing_variant_buttons(page, page_perms, is_parent=False, *args):
|
def page_listing_variant_buttons(page, page_perms, *args, **is_parent):
|
||||||
"""Adds page listing buttons to personalisable pages. Shows variants for
|
"""Adds page listing buttons to personalisable pages. Shows variants for
|
||||||
the page (if any) and a 'Create a new variant' button.
|
the page (if any) and a 'Create a new variant' button.
|
||||||
|
|
||||||
@@ -143,16 +151,28 @@ def page_listing_variant_buttons(page, page_perms, is_parent=False, *args):
|
|||||||
return
|
return
|
||||||
|
|
||||||
metadata = page.personalisation_metadata
|
metadata = page.personalisation_metadata
|
||||||
if metadata.is_canonical:
|
|
||||||
yield ButtonWithDropdownFromHook(
|
if WAGTAIL_VERSION >= (4, 0):
|
||||||
_("Variants"),
|
if metadata.is_canonical:
|
||||||
hook_name="register_page_listing_variant_buttons",
|
yield ButtonWithDropdownFromHook(
|
||||||
page=page,
|
_("Variants"),
|
||||||
page_perms=page_perms,
|
hook_name="register_page_listing_variant_buttons",
|
||||||
is_parent=is_parent,
|
page=page,
|
||||||
attrs={"target": "_blank", "title": _("Create or edit a variant")},
|
page_perms=page_perms,
|
||||||
priority=100,
|
attrs={"target": "_blank", "title": _("Create or edit a variant")},
|
||||||
)
|
priority=100,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if metadata.is_canonical:
|
||||||
|
yield ButtonWithDropdownFromHook(
|
||||||
|
_("Variants"),
|
||||||
|
hook_name="register_page_listing_variant_buttons",
|
||||||
|
page=page,
|
||||||
|
page_perms=page_perms,
|
||||||
|
is_parent=is_parent,
|
||||||
|
attrs={"target": "_blank", "title": _("Create or edit a variant")},
|
||||||
|
priority=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@hooks.register("register_page_listing_variant_buttons")
|
@hooks.register("register_page_listing_variant_buttons")
|
||||||
@@ -212,11 +232,14 @@ class CorrectedPagesSummaryItem(PagesSummaryItem):
|
|||||||
return page_count
|
return page_count
|
||||||
|
|
||||||
if WAGTAIL_VERSION >= (2, 15):
|
if WAGTAIL_VERSION >= (2, 15):
|
||||||
|
|
||||||
def get_context_data(self, parent_context):
|
def get_context_data(self, parent_context):
|
||||||
context = super().get_context_data(parent_context)
|
context = super().get_context_data(parent_context)
|
||||||
context["total_pages"] = self.get_total_pages(context)
|
context["total_pages"] = self.get_total_pages(context)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def get_context(self):
|
def get_context(self):
|
||||||
context = super().get_context()
|
context = super().get_context()
|
||||||
context["total_pages"] = self.get_total_pages(context)
|
context["total_pages"] = self.get_total_pages(context)
|
||||||
@@ -243,14 +266,25 @@ class SegmentSummaryPanel(SummaryItem):
|
|||||||
segment_count = models.Segment.objects.count()
|
segment_count = models.Segment.objects.count()
|
||||||
target_url = reverse("wagtail_personalisation_segment_modeladmin_index")
|
target_url = reverse("wagtail_personalisation_segment_modeladmin_index")
|
||||||
title = _("Segments")
|
title = _("Segments")
|
||||||
return mark_safe(
|
if WAGTAIL_VERSION >= (4, 0):
|
||||||
"""
|
return mark_safe(
|
||||||
<li class="icon icon-fa-snowflake-o">
|
"""
|
||||||
<a href="{}"><span>{}</span>{}</a>
|
<li>
|
||||||
</li>""".format(
|
<svg class="icon icon-tag icon" aria-hidden="true"><use href="#icon-tag"></use></svg>
|
||||||
target_url, segment_count, title
|
<a href="{}"><span>{}</span>{}</a>
|
||||||
|
</li>""".format(
|
||||||
|
target_url, segment_count, title
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return mark_safe(
|
||||||
|
"""
|
||||||
|
<li class="icon icon-fa-snowflake-o">
|
||||||
|
<a href="{}"><span>{}</span>{}</a>
|
||||||
|
</li>""".format(
|
||||||
|
target_url, segment_count, title
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PersonalisedPagesSummaryPanel(PagesSummaryItem):
|
class PersonalisedPagesSummaryPanel(PagesSummaryItem):
|
||||||
@@ -261,14 +295,25 @@ class PersonalisedPagesSummaryPanel(PagesSummaryItem):
|
|||||||
segment__isnull=True
|
segment__isnull=True
|
||||||
).count()
|
).count()
|
||||||
title = _("Personalised Page")
|
title = _("Personalised Page")
|
||||||
return mark_safe(
|
if WAGTAIL_VERSION >= (4, 0):
|
||||||
"""
|
return mark_safe(
|
||||||
<li class="icon icon-fa-file-o">
|
"""
|
||||||
<span>{}</span>{}{}
|
<li>
|
||||||
</li>""".format(
|
<svg class="icon icon-doc-empty icon" aria-hidden="true"><use href="#icon-doc-empty"></use></svg>
|
||||||
page_count, title, pluralize(page_count)
|
<a><span>{}</span>{}{}</a>
|
||||||
|
</li>""".format(
|
||||||
|
page_count, title, pluralize(page_count)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return mark_safe(
|
||||||
|
"""
|
||||||
|
<li class="icon icon-fa-file-o">
|
||||||
|
<span>{}</span>{}{}
|
||||||
|
</li>""".format(
|
||||||
|
page_count, title, pluralize(page_count)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class VariantPagesSummaryPanel(PagesSummaryItem):
|
class VariantPagesSummaryPanel(PagesSummaryItem):
|
||||||
@@ -279,14 +324,25 @@ class VariantPagesSummaryPanel(PagesSummaryItem):
|
|||||||
segment__isnull=False
|
segment__isnull=False
|
||||||
).count()
|
).count()
|
||||||
title = _("Variant")
|
title = _("Variant")
|
||||||
return mark_safe(
|
if WAGTAIL_VERSION >= (4, 0):
|
||||||
"""
|
return mark_safe(
|
||||||
<li class="icon icon-fa-files-o">
|
"""
|
||||||
<span>{}</span>{}{}
|
<li>
|
||||||
</li>""".format(
|
<svg class="icon icon-doc-empty icon" aria-hidden="true"><use href="#icon-doc-empty"></use></svg>
|
||||||
page_count, title, pluralize(page_count)
|
<a><span>{}</span>{}{}</a>
|
||||||
|
</li>""".format(
|
||||||
|
page_count, title, pluralize(page_count)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return mark_safe(
|
||||||
|
"""
|
||||||
|
<li class="icon icon-fa-files-o">
|
||||||
|
<span>{}</span>{}{}
|
||||||
|
</li>""".format(
|
||||||
|
page_count, title, pluralize(page_count)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@hooks.register("construct_homepage_summary_items")
|
@hooks.register("construct_homepage_summary_items")
|
||||||
|
Reference in New Issue
Block a user