diff --git a/bakerydemo/blog/models.py b/bakerydemo/blog/models.py index f8d7fa4..f4e761f 100644 --- a/bakerydemo/blog/models.py +++ b/bakerydemo/blog/models.py @@ -116,7 +116,7 @@ class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page): def get_context(self, request): context = super(BlogIndexPage, self).get_context(request) - context['blogs'] = BlogPage.objects.descendant_of( + context['posts'] = BlogPage.objects.descendant_of( self).live().order_by( '-date_published') return context @@ -125,9 +125,9 @@ class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page): @route('^tags/(\w+)/$', name='tag_archive') def tag_archive(self, request, tag=None): """ - A Custom view that utilizes Tags. This view will - return all related BlogPages for a given Tag or redirect back to - the BlogIndexPage + A Custom view that utilizes Tags. + This view will return all related BlogPages for a given Tag or + redirect back to the BlogIndexPage. """ try: @@ -138,29 +138,30 @@ class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page): messages.add_message(request, messages.INFO, msg) return redirect(self.url) - blogs = self.blogs(tag=tag) + posts = self.get_posts(tag=tag) context = { 'tag': tag, - 'blogs': blogs + 'posts': posts } return render(request, 'blog/blog_index_page.html', context) - def blogs(self, tag=None): + def get_posts(self, tag=None): """ - Return the child BlogPage objects for this BlogPageIndex. Optional - filter by tag + Return the child BlogPage objects for this BlogPageIndex. + Optional filter by tag. """ - blogs = BlogPage.objects.live().descendant_of(self) + + posts = BlogPage.objects.live().descendant_of(self) if tag: - blogs = blogs.filter(tags=tag) - return blogs + posts = posts.filter(tags=tag) + return posts def get_child_tags(self): """ Returns the list of Tags for child pages. """ - tags = [x.get_tags for x in self.blogs()] + tags = [x.get_tags for x in self.get_posts()] tags = [item for sublist in tags for item in sublist] tags = sorted(set(tags)) return tags diff --git a/bakerydemo/templates/blog/blog_index_page.html b/bakerydemo/templates/blog/blog_index_page.html index e73c30d..d3761cd 100644 --- a/bakerydemo/templates/blog/blog_index_page.html +++ b/bakerydemo/templates/blog/blog_index_page.html @@ -5,51 +5,49 @@ {% include "base/include/header-index.html" %}
- {% if tag %} -
-
-

Viewing all blog posts by {{ tag }}

-
-
- {% endif %} - - {% if page.get_child_tags %} - - {% endif %} - -
- {% if blogs %} - {% for blog in blogs %} -
  • - -
    - {% image blog.image fill-850x450-c50 as image %} - {{ image.alt }} -
    -
    -

    {{ blog.title }}

    -

    {{ blog.introduction|truncatewords:15 }}

    -
    - - - -
    -
  • - {% endfor %} - {% else %} -
    -

    Oh, snap. Looks like we were too busy baking to write any blog posts. Sorry.

    + {% if tag %} +
    +
    +

    Viewing all blog posts by {{ tag }}

    +
    {% endif %} + + {% if page.get_child_tags %} +
      + {% for tag in page.get_child_tags %} +
    • {{ tag }}
    • + {% endfor %} +
    + {% endif %} + +
    {% endblock content %}