Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Adds a category filter for NewsBlogFeaturedArticlesPlugin and NewsBlogLatestArticlesPlugin #498

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

corentin-cres
Copy link

Allows the configuration of a filter on categories for the plugins based on NewsBlogCMSPlugin.

This filter is either :

  • A list of categories (multiple choice field) for this specific plugin ;
  • Or can be dynamically determined for a given request. (Boolean field)

If the dynamic determination is specified, the list of categories will be ignored.
If no category is selected, it will not use any filter on categories ; so you won't have to go through your existing NewsBlogCMSPlugins on your website to update the configuration.

Dynamic configuration

This functionality is based on a new setting, ALDRYN_NEWSBLOG_CATEGORIES_FROM_REQUEST.
For example, if you map some categories in your page (page model has a categories multiple choice field) ; you will be able to use this mapping in your NewsBlogLatestArticlePlugin.

In this example, just set in your settings.py :

ALDRYN_NEWSBLOG_CATEGORIES_FROM_REQUEST = 'current_page.categories'

Basically, it will getattr(request, ALDRYN_NEWSBLOG_CATEGORIES_FROM_REQUEST).
So, in this example, it will filter using request.current_page.categories.

If the setting ALDRYN_NEWSBLOG_CATEGORIES_FROM_REQUEST is left empty, it will be ignored by the plugin and it will fallback using the defined list of categories.
The same goes if request.current_page.categories is set to an empty list of categories.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant