From 4e5454b3486ce891fcb9efdcb4e5a24d45190320 Mon Sep 17 00:00:00 2001 From: Tomasz Knapik Date: Wed, 30 May 2018 20:11:47 +0100 Subject: [PATCH] Use Wagtail's logic in the page count in the dash This adds a check if root page is root page in order to calculate the count properly the same way as Wagtail does [1]. [1] https://github.com/wagtail/wagtail/blob/5c9ff23e229acabad406c42c4e13cbaea32e6c15/wagtail/admin/site_summary.py#L38 --- src/wagtail_personalisation/wagtail_hooks.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wagtail_personalisation/wagtail_hooks.py b/src/wagtail_personalisation/wagtail_hooks.py index 5ea4c8d..0817207 100644 --- a/src/wagtail_personalisation/wagtail_hooks.py +++ b/src/wagtail_personalisation/wagtail_hooks.py @@ -173,8 +173,11 @@ class CorrectedPagesSummaryPanel(PagesSummaryItem): context = super(CorrectedPagesSummaryPanel, self).get_context() pages = utils.exclude_variants(Page.objects.all().specific()) - - context['total_pages'] = len(pages) - 1 + context['total_pages'] = len(pages) + # Perform the same check as Wagtail to get the correct count. + # https://github.com/wagtail/wagtail/blob/5c9ff23e229acabad406c42c4e13cbaea32e6c15/wagtail/admin/site_summary.py#L38 + if context.get('root_page') and context['root_page'].is_root(): + context['total_pages'] -= 1 return context