Show number of blog posts on admin dashboard
This commit is contained in:
parent
f3b248110e
commit
77e34cbf02
2 changed files with 30 additions and 1 deletions
|
@ -0,0 +1,8 @@
|
|||
{% load wagtailcore_tags wagtailadmin_tags %}
|
||||
|
||||
<li>
|
||||
{% icon name="edit" %}
|
||||
<a href="{% pageurl list_page %}">
|
||||
<span>{{ posts }}</span> Posts
|
||||
</a>
|
||||
</li>
|
|
@ -2,8 +2,9 @@ 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 BlogPostTagListPage
|
||||
from .models import BlogPostListPage, BlogPostTagListPage
|
||||
|
||||
|
||||
class BlogPostTagsMenuItem(MenuItem):
|
||||
|
@ -26,6 +27,26 @@ class BlogPostTagsMenuItem(MenuItem):
|
|||
return bool(self.url)
|
||||
|
||||
|
||||
class BlogPostCountSummaryItem(SummaryItem):
|
||||
template_name = "blog/blog_post_count_summary_item.html"
|
||||
|
||||
def is_shown(self) -> bool:
|
||||
return BlogPostListPage.objects.exists()
|
||||
|
||||
def get_context_data(self, parent_context: dict) -> dict:
|
||||
context = super().get_context_data(parent_context)
|
||||
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()
|
||||
|
||||
|
||||
@hooks.register("construct_homepage_summary_items")
|
||||
def register_blog_post_count_summary_item(request: HttpRequest, panels: list) -> None:
|
||||
panels.append(BlogPostCountSummaryItem(request))
|
||||
|
|
Loading…
Reference in a new issue