From 100c004f3af0caa579c87919e09153d67f146b4f Mon Sep 17 00:00:00 2001 From: Max Vyaznikov Date: Thu, 27 Feb 2014 16:38:52 +0300 Subject: [PATCH] settings fix + new param `BLOG_POSTS_LIST_TRUNCWORDS_COUNT` for shorting blog post in posts_list --- djangocms_blog/settings.py | 19 +++++++++++-------- .../djangocms_blog/includes/blog_item.html | 9 ++++++++- .../templates/djangocms_blog/post_list.html | 2 +- djangocms_blog/views.py | 6 +++++- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/djangocms_blog/settings.py b/djangocms_blog/settings.py index bc37158..235e8b3 100644 --- a/djangocms_blog/settings.py +++ b/djangocms_blog/settings.py @@ -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 \ No newline at end of file +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) diff --git a/djangocms_blog/templates/djangocms_blog/includes/blog_item.html b/djangocms_blog/templates/djangocms_blog/includes/blog_item.html index ca5f339..34bac70 100644 --- a/djangocms_blog/templates/djangocms_blog/includes/blog_item.html +++ b/djangocms_blog/templates/djangocms_blog/includes/blog_item.html @@ -33,7 +33,14 @@ {{ post.main_image.default_alt_text }} {% endif %} -
{% render_model post "abstract" %}
+
+ {% render_model post "abstract" as full_text %} + {% if not TRUNCWORDS_COUNT %} + {{ full_text }} + {% else %} + {{ full_text|truncatewords_html:TRUNCWORDS_COUNT }} + {% endif %} +
diff --git a/djangocms_blog/templates/djangocms_blog/post_list.html b/djangocms_blog/templates/djangocms_blog/post_list.html index a4a2b2a..c735cd5 100644 --- a/djangocms_blog/templates/djangocms_blog/post_list.html +++ b/djangocms_blog/templates/djangocms_blog/post_list.html @@ -14,7 +14,7 @@ {% 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 %}

{% trans "No article found." %}

{% endfor %} diff --git a/djangocms_blog/views.py b/djangocms_blog/views.py index ada03d8..cc3f6b5 100644 --- a/djangocms_blog/views.py +++ b/djangocms_blog/views.py @@ -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