From 0cc6086aabfeb1e1c5a9774d23f1b5ad701fa836 Mon Sep 17 00:00:00 2001 From: cb Date: Tue, 17 Dec 2019 10:27:16 +0100 Subject: [PATCH 1/3] Author Blog Articles plugin improvement added X last blog posts in context, so that templates can display posts instead of only the total number of blog posts written by the selected authors --- djangocms_blog/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index a63acd89..42a40ea9 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -562,7 +562,10 @@ def get_authors(self): qs = qs.published(current_site=False) count = qs.count() if count: + # total nb of articles author.count = count + # "the number of author articles to be displayed" + author.posts = qs[:self.latest_posts] return authors From a320627221f399ced3636162630207e986794475 Mon Sep 17 00:00:00 2001 From: cb Date: Wed, 18 Dec 2019 13:04:20 +0100 Subject: [PATCH 2/3] replace dead link in development.rst --- docs/development.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/development.rst b/docs/development.rst index 0b42a0de..fac78d0d 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -26,8 +26,8 @@ policies. These include: -* `guidelines and policies - `_ for contributing +* `development policies + `_ for contributing to the project, including standards for code and documentation * standards for `managing the project's development `_ From 537aa1c4c943df100870ae9e23ca106864b4c639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20PALMIER?= < fp@kapt.mobi> Date: Mon, 6 Apr 2020 12:29:15 +0000 Subject: [PATCH 3/3] FEAT : Add category feeds --- djangocms_blog/feeds.py | 24 +++++++++++++++++++++--- djangocms_blog/settings.py | 3 ++- djangocms_blog/urls.py | 8 +++++++- docs/settings.rst | 3 ++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/djangocms_blog/feeds.py b/djangocms_blog/feeds.py index 798f3dba..897a8c2d 100644 --- a/djangocms_blog/feeds.py +++ b/djangocms_blog/feeds.py @@ -80,11 +80,29 @@ def item_author_url(self, item): class TagFeed(LatestEntriesFeed): feed_items_number = get_setting('FEED_TAGS_ITEMS') - def get_object(self, request, tag): - return tag # pragma: no cover + def get_object(self, request, tag, feed_items_number=None): + if feed_items_number is None: + feed_items_number = get_setting('FEED_TAGS_ITEMS') + + return {'tag': tag, 'feed_items_number': int(feed_items_number)} + + def items(self, obj=None): + return Post.objects.published().filter(tags__slug=obj['tag'])[ + : obj['feed_items_number'] + ] + + +class CategoryFeed(LatestEntriesFeed): + def get_object(self, request, category, feed_items_number=None): + if feed_items_number is None: + feed_items_number = get_setting('FEED_CATEGORY_ITEMS') + + return {'category': category, 'feed_items_number': int(feed_items_number)} def items(self, obj=None): - return Post.objects.published().filter(tags__slug=obj)[:self.feed_items_number] + return Post.objects.published().filter( + categories__translations__slug=obj['category'] + )[: obj['feed_items_number']] class FBInstantFeed(Rss201rev2Feed): diff --git a/djangocms_blog/settings.py b/djangocms_blog/settings.py index 1567f6ee..2f2e85ad 100644 --- a/djangocms_blog/settings.py +++ b/djangocms_blog/settings.py @@ -154,9 +154,10 @@ def get_setting(name): settings, 'BLOG_FEED_LATEST_ITEMS', 10), 'BLOG_FEED_TAGS_ITEMS': getattr( settings, 'BLOG_FEED_TAGS_ITEMS', 10), + 'BLOG_FEED_CATEGORY_ITEMS': getattr( + settings, 'BLOG_FEED_CATEGORY_ITEMS', 10), 'BLOG_LIVEBLOG_PLUGINS': getattr( settings, 'BLOG_LIVEBLOG_PLUGINS', ('LiveblogPlugin',)), - 'BLOG_PLUGIN_TEMPLATE_FOLDERS': getattr( settings, 'BLOG_PLUGIN_TEMPLATE_FOLDERS', (('plugins', _('Default template')),)), diff --git a/djangocms_blog/urls.py b/djangocms_blog/urls.py index 522d7a36..6503f834 100644 --- a/djangocms_blog/urls.py +++ b/djangocms_blog/urls.py @@ -3,7 +3,7 @@ from django.conf.urls import url -from .feeds import FBInstantArticles, LatestEntriesFeed, TagFeed +from .feeds import FBInstantArticles, LatestEntriesFeed, TagFeed, CategoryFeed from .settings import get_setting from .views import ( AuthorEntriesView, CategoryEntriesView, PostArchiveView, PostDetailView, PostListView, @@ -40,8 +40,14 @@ def get_urls(): AuthorEntriesView.as_view(), name='posts-author'), url(r'^category/(?P[\w\.@+-]+)/$', CategoryEntriesView.as_view(), name='posts-category'), + url(r'^category/(?P[\w\.@+-]+)/feed/$', + CategoryFeed(), name='posts-category-feed'), + url(r'^category/(?P[\w\.@+-]+)/feed/(?P\d{1,4})/$', + CategoryFeed(), name='posts-category-feed-items-number'), url(r'^tag/(?P[-\w]+)/$', TaggedListView.as_view(), name='posts-tagged'), url(r'^tag/(?P[-\w]+)/feed/$', TagFeed(), name='posts-tagged-feed'), + url(r'^tag/(?P[-\w]+)/feed/(?P\d{1,4})/$', + TagFeed(), name='posts-tagged-feed-items-number') ] + detail_urls diff --git a/docs/settings.rst b/docs/settings.rst index fadcb3e5..c75ad877 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -93,7 +93,8 @@ Global Settings * BLOG_FEED_CACHE_TIMEOUT: Cache timeout for RSS feeds * BLOG_FEED_INSTANT_ITEMS: Number of items in Instant Article feed * BLOG_FEED_LATEST_ITEMS: Number of items in latest items feed -* BLOG_FEED_TAGS_ITEMS: Number of items in per tags feed +* BLOG_FEED_TAGS_ITEMS: Number of items in per tags feed (default: ``10``) +* BLOG_FEED_CATEGORY_ITEMS: Number of items in per category feed (default: ``10``) * BLOG_PLUGIN_TEMPLATE_FOLDERS: (Sub-)folder from which the plugin templates are loaded. The default folder is ``plugins``. It goes into the ``djangocms_blog`` template folder (or, if set, the folder named in the app hook). This allows, e.g., different templates for showing a post list as tables, columns, ... . New templates have the same names as the standard templates in the ``plugins`` folder (``latest_entries.html``, ``authors.html``, ``tags.html``, ``categories.html``, ``archive.html``). Default behavior corresponds to this setting being ``( ("plugins", _("Default template") )``. To add new templates add to this setting, e.g., ``('timeline', _('Vertical timeline') )``. * BLOG_META_DESCRIPTION_LENGTH: Maximum length for the Meta description field (default: ``320``) * BLOG_META_TITLE_LENGTH: Maximum length for the Meta title field (default: ``70``)