Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Category feed v2 #544

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions djangocms_blog/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,29 @@ def item_author_url(self, item):
class TagFeed(LatestEntriesFeed):
feed_items_number = get_setting('FEED_TAGS_ITEMS')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you are using directly the setting, you can also remove this attribute


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):
Expand Down
3 changes: 3 additions & 0 deletions djangocms_blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this does not belong here

return authors


Expand Down
3 changes: 2 additions & 1 deletion djangocms_blog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),)),

Expand Down
8 changes: 7 additions & 1 deletion djangocms_blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -40,8 +40,14 @@ def get_urls():
AuthorEntriesView.as_view(), name='posts-author'),
url(r'^category/(?P<category>[\w\.@+-]+)/$',
CategoryEntriesView.as_view(), name='posts-category'),
url(r'^category/(?P<category>[\w\.@+-]+)/feed/$',
CategoryFeed(), name='posts-category-feed'),
url(r'^category/(?P<category>[\w\.@+-]+)/feed/(?P<feed_items_number>\d{1,4})/$',
CategoryFeed(), name='posts-category-feed-items-number'),
url(r'^tag/(?P<tag>[-\w]+)/$',
TaggedListView.as_view(), name='posts-tagged'),
url(r'^tag/(?P<tag>[-\w]+)/feed/$',
TagFeed(), name='posts-tagged-feed'),
url(r'^tag/(?P<tag>[-\w]+)/feed/(?P<feed_items_number>\d{1,4})/$',
TagFeed(), name='posts-tagged-feed-items-number')
] + detail_urls
4 changes: 2 additions & 2 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ policies.

These include:

* `guidelines and policies
<http://docs.django-cms.org/en/latest/contributing/contributing.html>`_ for contributing
* `development policies
<http://docs.django-cms.org/en/latest/contributing/development-policies.html>`_ for contributing
to the project, including standards for code and documentation
* standards for `managing the project's development
<http://docs.django-cms.org/en/latest/contributing/management.html>`_
Expand Down
3 changes: 2 additions & 1 deletion docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``)
Expand Down