Rename blogs method to get_posts; tweak indentation

pull/69/head
Scot Hacker 2017-02-23 23:31:23 -08:00
rodzic e39840882c
commit 07e6823751
2 zmienionych plików z 55 dodań i 56 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -22,8 +22,8 @@
{% endif %}
<div class="row row-eq-height blog-list">
{% if blogs %}
{% for blog in blogs %}
{% if posts %}
{% for blog in posts %}
<li class="col-xs-12 col-sm-6 col-md-3 blog-list-item">
<a href="{% pageurl blog %}">
<div class="image">
@ -34,14 +34,12 @@
<h2 class="blog-list-title">{{ blog.title }}</h2>
<p>{{ blog.introduction|truncatewords:15 }}</p>
</div>
<div class="small footer">
{{ blog.date_published }} by
{% for author in blog.authors %}
{{ author }}{% if not forloop.last %}, {% endif %}
{% endfor %}
</div>
</a>
</li>
{% endfor %}