kopia lustrzana https://github.com/wagtail/bakerydemo
Rename blogs method to get_posts; tweak indentation
rodzic
e39840882c
commit
07e6823751
|
@ -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
|
||||
|
|
|
@ -5,51 +5,49 @@
|
|||
{% include "base/include/header-index.html" %}
|
||||
|
||||
<div class="container">
|
||||
{% if tag %}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<p>Viewing all blog posts by <span class="outline">{{ tag }}</span></p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if page.get_child_tags %}
|
||||
<ul class="blog-tags tags list-inline">
|
||||
{% for tag in page.get_child_tags %}
|
||||
<li><a href="{{ tag.url }}">{{ tag }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
<div class="row row-eq-height blog-list">
|
||||
{% if blogs %}
|
||||
{% for blog in blogs %}
|
||||
<li class="col-xs-12 col-sm-6 col-md-3 blog-list-item">
|
||||
<a href="{% pageurl blog %}">
|
||||
<div class="image">
|
||||
{% image blog.image fill-850x450-c50 as image %}
|
||||
<img src="{{ image.url }}" width="{{ image.width }}" height="{{ image.height }}" alt="{{ image.alt }}" class="" />
|
||||
</div>
|
||||
<div class="text">
|
||||
<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 %}
|
||||
{% else %}
|
||||
<div class="col-md-12">
|
||||
<p>Oh, snap. Looks like we were too busy baking to write any blog posts. Sorry.</p>
|
||||
{% if tag %}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<p>Viewing all blog posts by <span class="outline">{{ tag }}</span></p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if page.get_child_tags %}
|
||||
<ul class="blog-tags tags list-inline">
|
||||
{% for tag in page.get_child_tags %}
|
||||
<li><a href="{{ tag.url }}">{{ tag }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
<div class="row row-eq-height blog-list">
|
||||
{% 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">
|
||||
{% image blog.image fill-850x450-c50 as image %}
|
||||
<img src="{{ image.url }}" width="{{ image.width }}" height="{{ image.height }}" alt="{{ image.alt }}" class="" />
|
||||
</div>
|
||||
<div class="text">
|
||||
<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 %}
|
||||
{% else %}
|
||||
<div class="col-md-12">
|
||||
<p>Oh, snap. Looks like we were too busy baking to write any blog posts. Sorry.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
Ładowanie…
Reference in New Issue