Replace tags menu item with dashboard item
This commit is contained in:
parent
3b02f21f81
commit
9cfa369d56
2 changed files with 21 additions and 26 deletions
|
@ -0,0 +1,8 @@
|
||||||
|
{% load wagtailadmin_tags %}
|
||||||
|
|
||||||
|
<li>
|
||||||
|
{% icon name="tag" %}
|
||||||
|
<a href="{% url 'wagtailadmin_explore' list_page.id %}">
|
||||||
|
<span>{{ tags }}</span> Tags
|
||||||
|
</a>
|
||||||
|
</li>
|
|
@ -1,32 +1,10 @@
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.urls import reverse
|
|
||||||
from wagtail import hooks
|
from wagtail import hooks
|
||||||
from wagtail.admin.menu import MenuItem
|
|
||||||
from wagtail.admin.site_summary import SummaryItem
|
from wagtail.admin.site_summary import SummaryItem
|
||||||
|
|
||||||
from .models import BlogPostListPage, BlogPostTagListPage
|
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):
|
class BlogPostCountSummaryItem(SummaryItem):
|
||||||
template_name = "blog/blog_post_count_summary_item.html"
|
template_name = "blog/blog_post_count_summary_item.html"
|
||||||
|
|
||||||
|
@ -38,15 +16,24 @@ class BlogPostCountSummaryItem(SummaryItem):
|
||||||
list_page = BlogPostListPage.objects.get()
|
list_page = BlogPostListPage.objects.get()
|
||||||
context["list_page"] = list_page
|
context["list_page"] = list_page
|
||||||
context["posts"] = list_page.get_listing_pages().count()
|
context["posts"] = list_page.get_listing_pages().count()
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
@hooks.register("register_admin_menu_item")
|
class BlogPostTagsCountSummaryItem(SummaryItem):
|
||||||
def register_blog_post_tags_menu_item() -> MenuItem:
|
template_name = "blog/blog_post_tags_count_summary_item.html"
|
||||||
return BlogPostTagsMenuItem()
|
|
||||||
|
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")
|
@hooks.register("construct_homepage_summary_items")
|
||||||
def register_blog_post_count_summary_item(request: HttpRequest, panels: list) -> None:
|
def register_blog_post_count_summary_item(request: HttpRequest, panels: list) -> None:
|
||||||
panels.append(BlogPostCountSummaryItem(request))
|
panels.append(BlogPostCountSummaryItem(request))
|
||||||
|
panels.append(BlogPostTagsCountSummaryItem(request))
|
||||||
|
|
Loading…
Reference in a new issue