settings fix + new param `BLOG_POSTS_LIST_TRUNCWORDS_COUNT` for shorting blog post in posts_list

This commit is contained in:
Max Vyaznikov 2014-02-27 16:38:52 +03:00
parent 94c967c7e6
commit 100c004f3a
4 changed files with 25 additions and 11 deletions

View File

@ -1,18 +1,21 @@
# -*- coding: utf-8 -*-
BLOG_IMAGE_THUMBNAIL_SIZE = {
from django.conf import settings
BLOG_IMAGE_THUMBNAIL_SIZE = getattr(settings, 'BLOG_IMAGE_THUMBNAIL_SIZE', {
'size': '120x120',
'crop': True,
'upscale': False
}
})
BLOG_IMAGE_FULL_SIZE = {
BLOG_IMAGE_FULL_SIZE = getattr(settings, 'BLOG_IMAGE_FULL_SIZE', {
'size': '640x120',
'crop': True,
'upscale': False
}
})
BLOG_TAGCLOUD_MIN = 1
BLOG_TAGCLOUD_MAX = 10
BLOG_PAGINATION = 10
BLOG_LATEST_POSTS = 5
BLOG_TAGCLOUD_MIN = getattr(settings, 'BLOG_TAGCLOUD_MIN', 1)
BLOG_TAGCLOUD_MAX = getattr(settings, 'BLOG_TAGCLOUD_MAX', 10)
BLOG_PAGINATION = getattr(settings, 'BLOG_PAGINATION', 10)
BLOG_LATEST_POSTS = getattr(settings, 'BLOG_LATEST_POSTS', 5)
BLOG_POSTS_LIST_TRUNCWORDS_COUNT = getattr(settings, 'BLOG_POSTS_LIST_TRUNCWORDS_COUNT', 100)

View File

@ -33,7 +33,14 @@
<img src="{{ thumb.url }}" alt="{{ post.main_image.default_alt_text }}" width="{{ thumb.width }}" height="{{ thumb.height }}" />
</div>
{% endif %}
<div class="blog-lead">{% render_model post "abstract" %}</div>
<div class="blog-lead">
{% render_model post "abstract" as full_text %}
{% if not TRUNCWORDS_COUNT %}
{{ full_text }}
{% else %}
{{ full_text|truncatewords_html:TRUNCWORDS_COUNT }}
{% endif %}
</div>
<footer class="read-more">
<a href="{{ post.get_absolute_url }}">{% trans "read more" %} &raquo;</a>
</footer>

View File

@ -14,7 +14,7 @@
</header>
{% endblock %}
{% for post in post_list %}
{% include "djangocms_blog/includes/blog_item.html" with post=post image="true" %}
{% include "djangocms_blog/includes/blog_item.html" with post=post image="true" TRUNCWORDS_COUNT=TRUNCWORDS_COUNT %}
{% empty %}
<p class="blog-empty">{% trans "No article found." %}</p>
{% endfor %}

View File

@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView, DetailView
from .models import Post, BlogCategory
from .settings import BLOG_PAGINATION
from .settings import BLOG_PAGINATION, BLOG_POSTS_LIST_TRUNCWORDS_COUNT
class BaseBlogView(object):
@ -31,6 +31,10 @@ class PostListView(BaseBlogView, ListView):
template_name = "djangocms_blog/post_list.html"
paginate_by = BLOG_PAGINATION
def get_context_data(self, **kwargs):
context = super(PostListView, self).get_context_data(**kwargs)
context['TRUNCWORDS_COUNT'] = BLOG_POSTS_LIST_TRUNCWORDS_COUNT
return context
class PostDetailView(BaseBlogView, DetailView):
model = Post