diff --git a/website/blog/templates/blog/blog_post_tags_count_summary_item.html b/website/blog/templates/blog/blog_post_tags_count_summary_item.html
new file mode 100644
index 0000000..a91b760
--- /dev/null
+++ b/website/blog/templates/blog/blog_post_tags_count_summary_item.html
@@ -0,0 +1,8 @@
+{% load wagtailadmin_tags %}
+
+
+ {% icon name="tag" %}
+
+ {{ tags }} Tags
+
+
diff --git a/website/blog/wagtail_hooks.py b/website/blog/wagtail_hooks.py
index 4f22cc3..3a9bbd4 100644
--- a/website/blog/wagtail_hooks.py
+++ b/website/blog/wagtail_hooks.py
@@ -1,32 +1,10 @@
from django.http.request import HttpRequest
-from django.urls import reverse
from wagtail import hooks
-from wagtail.admin.menu import MenuItem
from wagtail.admin.site_summary import SummaryItem
from .models import BlogPostListPage, BlogPostTagListPage
-class BlogPostTagsMenuItem(MenuItem):
- url: str
-
- def __init__(self) -> None:
- super().__init__("Blog post tags", url="", icon_name="tag")
-
- def is_shown(self, request: HttpRequest) -> bool:
- if not self.url:
- blog_post_tag_list_id = (
- BlogPostTagListPage.objects.live().values_list("id", flat=True).first()
- )
- self.url = (
- reverse("wagtailadmin_explore", args=[blog_post_tag_list_id])
- if blog_post_tag_list_id
- else ""
- )
-
- return bool(self.url)
-
-
class BlogPostCountSummaryItem(SummaryItem):
template_name = "blog/blog_post_count_summary_item.html"
@@ -38,15 +16,24 @@ class BlogPostCountSummaryItem(SummaryItem):
list_page = BlogPostListPage.objects.get()
context["list_page"] = list_page
context["posts"] = list_page.get_listing_pages().count()
-
return context
-@hooks.register("register_admin_menu_item")
-def register_blog_post_tags_menu_item() -> MenuItem:
- return BlogPostTagsMenuItem()
+class BlogPostTagsCountSummaryItem(SummaryItem):
+ template_name = "blog/blog_post_tags_count_summary_item.html"
+
+ def is_shown(self) -> bool:
+ return BlogPostTagListPage.objects.exists()
+
+ def get_context_data(self, parent_context: dict) -> dict:
+ context = super().get_context_data(parent_context)
+ list_page = BlogPostTagListPage.objects.get()
+ context["list_page"] = list_page
+ context["tags"] = list_page.get_listing_pages().count()
+ return context
@hooks.register("construct_homepage_summary_items")
def register_blog_post_count_summary_item(request: HttpRequest, panels: list) -> None:
panels.append(BlogPostCountSummaryItem(request))
+ panels.append(BlogPostTagsCountSummaryItem(request))