Fix issues with public tags in templates
This commit is contained in:
parent
4c600651b6
commit
0424c2dba2
3 changed files with 19 additions and 4 deletions
|
@ -7,6 +7,7 @@ from django.utils import timezone
|
|||
from django.utils.functional import cached_property
|
||||
from modelcluster.fields import ParentalManyToManyField
|
||||
from wagtail.admin.panels import FieldPanel
|
||||
from wagtail.models import PageQuerySet
|
||||
from wagtail.search import index
|
||||
from wagtailautocomplete.edit_handlers import AutocompletePanel
|
||||
|
||||
|
@ -61,6 +62,19 @@ class BlogPostPage(BaseContentPage):
|
|||
def tag_list_page_url(self) -> Optional[str]:
|
||||
return SingletonPageCache.get_url(BlogPostTagListPage)
|
||||
|
||||
@cached_property
|
||||
def tags_list(self) -> models.QuerySet:
|
||||
"""
|
||||
Use this to get a page's tags.
|
||||
"""
|
||||
tags = self.tags.order_by("slug")
|
||||
|
||||
# In drafts, `django-modelcluster` doesn't support these filters
|
||||
if isinstance(tags, PageQuerySet):
|
||||
return tags.public().live()
|
||||
|
||||
return tags
|
||||
|
||||
@cached_property
|
||||
def blog_post_list_page_url(self) -> Optional[str]:
|
||||
return SingletonPageCache.get_url(BlogPostListPage)
|
||||
|
|
|
@ -20,14 +20,14 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if page.tags.public.live.all %}
|
||||
{% if page.tags_list %}
|
||||
<div class="icon-text is-family-code">
|
||||
<span class="icon">
|
||||
<a href="{{ page.tag_list_page_url }}" title="View all tags">
|
||||
<i class="fas fa-lg fa-tags"></i>
|
||||
</a>
|
||||
</span>
|
||||
{% for tag in page.tags.public.live.all|dictsort:"slug" %}
|
||||
{% for tag in page.tags_list %}
|
||||
<span><a title="{{ tag.name }}" href="{% pageurl tag %}">#{{ tag.slug }}</a></span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
|
@ -15,6 +15,7 @@ from wagtail.query import PageQuerySet
|
|||
from wagtail_favicon.models import FaviconSettings
|
||||
from wagtail_favicon.utils import get_rendition_url
|
||||
|
||||
from website.blog.models import BlogPostPage
|
||||
from website.common.utils import get_site_title
|
||||
from website.contrib.singleton_page.utils import SingletonPageCache
|
||||
from website.home.models import HomePage
|
||||
|
@ -126,8 +127,8 @@ class AllPagesFeed(Feed):
|
|||
return getattr(item, "summary", None) or item.title
|
||||
|
||||
def item_categories(self, item: BasePage) -> Optional[list[str]]:
|
||||
if tags := getattr(item, "tags", None):
|
||||
return tags.public().live().order_by("slug").values_list("slug", flat=True)
|
||||
if isinstance(item, BlogPostPage):
|
||||
return item.tags_list.values_list("slug", flat=True)
|
||||
return None
|
||||
|
||||
def item_enclosure_url(self, item: BasePage) -> Optional[str]:
|
||||
|
|
Loading…
Reference in a new issue