From 078af3e8f5aa001942462dfdfaf17f30ea85122b Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 3 Aug 2018 20:28:10 +0100 Subject: [PATCH] Refactor tag route to standard querystring on view --- project/blog/models.py | 14 +++++--------- project/settings.py | 1 - templates/blog/blog_index_page.html | 4 ++-- templates/common/content-details.html | 4 +++- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/project/blog/models.py b/project/blog/models.py index 37bfdbd..4264fea 100644 --- a/project/blog/models.py +++ b/project/blog/models.py @@ -39,7 +39,7 @@ class BlogPage(Entity): return self.post_date.strftime("%Y-%m") -class BlogIndexPage(RoutablePageMixin, Entity): +class BlogIndexPage(Entity): body = build_stream_field() subpage_types = [BlogPage] @@ -48,16 +48,12 @@ class BlogIndexPage(RoutablePageMixin, Entity): 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): context = super().get_context(request) child_pages = self.get_children().specific().live().values_list('id', flat=True) context['blogs'] = BlogPage.objects.filter(id__in=child_pages) - if hasattr(self, 'tag_filter'): - context['tag'] = self.tag_filter - context['blogs'] = context['blogs'].filter(tags__name=self.tag_filter) + tag_filter = request.GET.get('tag') + if tag_filter: + context['tag'] = tag_filter + context['blogs'] = context['blogs'].filter(tags__name=tag_filter) return context diff --git a/project/settings.py b/project/settings.py index 8807f6b..7f9c3e6 100644 --- a/project/settings.py +++ b/project/settings.py @@ -49,7 +49,6 @@ INSTALLED_APPS = [ 'wagtail.contrib.forms', 'wagtail.contrib.redirects', - 'wagtail.contrib.routable_page', 'wagtail.embeds', 'wagtail.sites', 'wagtail.users', diff --git a/templates/blog/blog_index_page.html b/templates/blog/blog_index_page.html index b2d59c6..4c0b575 100644 --- a/templates/blog/blog_index_page.html +++ b/templates/blog/blog_index_page.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% load static wagtailimages_tags %} +{% load static wagtailimages_tags wagtailcore_tags %} {% block content %}
@@ -11,7 +11,7 @@
{% endif %}

{{ page.title }}

-
Posts tagged with #{{ tag }}
+
Posts tagged with #{{ tag }}
{% else %} {% include "common/content.html" %} {% endif %} diff --git a/templates/common/content-details.html b/templates/common/content-details.html index 923c46a..e2a7626 100644 --- a/templates/common/content-details.html +++ b/templates/common/content-details.html @@ -1,9 +1,11 @@ +{% load wagtailcore_tags %} + {% if page.post_date %} {{ page.post_date }} {% endif %} {% if page.tags.all.exists %} {% for tag in page.tags.all %} - #{{ tag }} + #{{ tag }} {% endfor %} {% endif %}