Refactor tag route to standard querystring on view
This commit is contained in:
parent
670efc0928
commit
078af3e8f5
4 changed files with 10 additions and 13 deletions
|
@ -39,7 +39,7 @@ class BlogPage(Entity):
|
||||||
return self.post_date.strftime("%Y-%m")
|
return self.post_date.strftime("%Y-%m")
|
||||||
|
|
||||||
|
|
||||||
class BlogIndexPage(RoutablePageMixin, Entity):
|
class BlogIndexPage(Entity):
|
||||||
body = build_stream_field()
|
body = build_stream_field()
|
||||||
|
|
||||||
subpage_types = [BlogPage]
|
subpage_types = [BlogPage]
|
||||||
|
@ -48,16 +48,12 @@ class BlogIndexPage(RoutablePageMixin, Entity):
|
||||||
StreamFieldPanel('body')
|
StreamFieldPanel('body')
|
||||||
]
|
]
|
||||||
|
|
||||||
@route(r'^tag/(\w+)/$')
|
|
||||||
def tags(self, request, *args, **kwargs):
|
|
||||||
self.tag_filter = args[0]
|
|
||||||
return Entity.serve(self, request, *args, **kwargs)
|
|
||||||
|
|
||||||
def get_context(self, request, *args, **kwargs):
|
def get_context(self, request, *args, **kwargs):
|
||||||
context = super().get_context(request)
|
context = super().get_context(request)
|
||||||
child_pages = self.get_children().specific().live().values_list('id', flat=True)
|
child_pages = self.get_children().specific().live().values_list('id', flat=True)
|
||||||
context['blogs'] = BlogPage.objects.filter(id__in=child_pages)
|
context['blogs'] = BlogPage.objects.filter(id__in=child_pages)
|
||||||
if hasattr(self, 'tag_filter'):
|
tag_filter = request.GET.get('tag')
|
||||||
context['tag'] = self.tag_filter
|
if tag_filter:
|
||||||
context['blogs'] = context['blogs'].filter(tags__name=self.tag_filter)
|
context['tag'] = tag_filter
|
||||||
|
context['blogs'] = context['blogs'].filter(tags__name=tag_filter)
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -49,7 +49,6 @@ INSTALLED_APPS = [
|
||||||
|
|
||||||
'wagtail.contrib.forms',
|
'wagtail.contrib.forms',
|
||||||
'wagtail.contrib.redirects',
|
'wagtail.contrib.redirects',
|
||||||
'wagtail.contrib.routable_page',
|
|
||||||
'wagtail.embeds',
|
'wagtail.embeds',
|
||||||
'wagtail.sites',
|
'wagtail.sites',
|
||||||
'wagtail.users',
|
'wagtail.users',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% load static wagtailimages_tags %}
|
{% load static wagtailimages_tags wagtailcore_tags %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
<div class="mb-3 image header-image" data-image='{{ photo.url }}'></div>
|
<div class="mb-3 image header-image" data-image='{{ photo.url }}'></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h1 class="display-5">{{ page.title }}</h1>
|
<h1 class="display-5">{{ page.title }}</h1>
|
||||||
<h5 class="my-3">Posts tagged with <a href="">#{{ tag }}</a></h5>
|
<h5 class="my-3">Posts tagged with <a href="{% slugurl "blog" %}?tag={{ tag }}">#{{ tag }}</a></h5>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% include "common/content.html" %}
|
{% include "common/content.html" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
{% load wagtailcore_tags %}
|
||||||
|
|
||||||
{% if page.post_date %}
|
{% if page.post_date %}
|
||||||
<span class="pr-1" title='{{ page.post_date }}'>{{ page.post_date }}</span>
|
<span class="pr-1" title='{{ page.post_date }}'>{{ page.post_date }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if page.tags.all.exists %}
|
{% if page.tags.all.exists %}
|
||||||
{% for tag in page.tags.all %}
|
{% for tag in page.tags.all %}
|
||||||
<a href="" class="mr-1">#{{ tag }}</a>
|
<a href="{% slugurl "blog" %}?tag={{ tag }}" class="mr-1">#{{ tag }}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Reference in a new issue