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

Commit

Permalink
Merge pull request #379 from aldryn/feature/add-exclude-featured-arti…
Browse files Browse the repository at this point in the history
…cles-features

Add exlcude featured articles to config and latest articles plugin.
  • Loading branch information
Kirill Kniazev committed Apr 15, 2016
2 parents 9d9fb00 + ec9234a commit 83a437a
Show file tree
Hide file tree
Showing 9 changed files with 413 additions and 4 deletions.
5 changes: 3 additions & 2 deletions aldryn_newsblog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def get_config_fields(self):
return (
'app_title', 'permalink_type', 'non_permalink_handling',
'template_prefix', 'paginate_by', 'pagination_pages_start',
'pagination_pages_visible', 'create_authors', 'search_indexed',
'config.default_published', )
'pagination_pages_visible', 'exclude_featured',
'create_authors', 'search_indexed', 'config.default_published',
)

admin.site.register(models.NewsBlogConfig, NewsBlogConfigAdmin)
11 changes: 10 additions & 1 deletion aldryn_newsblog/cms_appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@ class NewsBlogConfig(TranslatableModel, AppHookConfig):
help_text=_('When grouping page numbers, this determines how many '
'pages are visible on each side of the active page.'),
)

exclude_featured = models.PositiveSmallIntegerField(
_('Excluded featured articles count'),
blank=True,
default=0,
help_text=_(
'If you are using the Featured Articles plugin on the article list '
'view, you may prefer to exclude featured articles from the '
'article list itself to avoid duplicates. To do this, enter the '
'same number here as in your Featured Articles plugin.'),
)
template_prefix = models.CharField(
max_length=20,
null=True, blank=True,
Expand Down
2 changes: 1 addition & 1 deletion aldryn_newsblog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NewsBlogLatestArticlesPluginForm(AutoAppConfigFormMixin,
forms.ModelForm):
class Meta:
model = models.NewsBlogLatestArticlesPlugin
fields = ['app_config', 'latest_articles']
fields = ['app_config', 'latest_articles', 'exclude_featured']


class NewsBlogTagsPluginForm(AutoAppConfigFormMixin, forms.ModelForm):
Expand Down
39 changes: 39 additions & 0 deletions aldryn_newsblog/migrations/0011_auto_20160412_1622.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import djangocms_text_ckeditor.fields


class Migration(migrations.Migration):

dependencies = [
('aldryn_newsblog', '0010_auto_20160316_0935'),
]

operations = [
migrations.AddField(
model_name='newsblogconfig',
name='exclude_featured',
field=models.PositiveSmallIntegerField(default=0, help_text='If you are using the Featured Articles plugin on the article list view, you may prefer to exclude featured articles from the article list itself to avoid duplicates. To do this, enter the same number here as in your Featured Articles plugin.', verbose_name='Excluded featured articles count', blank=True),
preserve_default=True,
),
migrations.AddField(
model_name='newsbloglatestarticlesplugin',
name='exclude_featured',
field=models.PositiveSmallIntegerField(default=0, help_text='The maximum number of featured articles to exclude from display. E.g. for uses in combination with featured articles plugin.', blank=True),
preserve_default=True,
),
migrations.AlterField(
model_name='articletranslation',
name='lead_in',
field=djangocms_text_ckeditor.fields.HTMLField(default='', help_text='The lead gives the reader the main idea of the story, this is useful in overviews, lists or as an introduction to your article.', verbose_name='lead', blank=True),
preserve_default=True,
),
migrations.AlterField(
model_name='newsblogconfig',
name='template_prefix',
field=models.CharField(max_length=20, null=True, verbose_name='Prefix for template dirs', blank=True),
preserve_default=True,
),
]
14 changes: 14 additions & 0 deletions aldryn_newsblog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,35 @@ class NewsBlogLatestArticlesPlugin(PluginEditModeMixin, NewsBlogCMSPlugin):
default=5,
help_text=_('The maximum number of latest articles to display.')
)
exclude_featured = models.PositiveSmallIntegerField(
default=0,
blank=True,
help_text=_(
'The maximum number of featured articles to exclude from display. '
'E.g. for uses in combination with featured articles plugin.')
)

def get_articles(self, request):
"""
Returns a queryset of the latest N articles. N is the plugin setting:
latest_articles.
"""
queryset = Article.objects
featured_qs = Article.objects.all().filter(is_featured=True)
if not self.get_edit_mode(request):
queryset = queryset.published()
featured_qs = featured_qs.published()
languages = get_valid_languages_from_request(
self.app_config.namespace, request)
if self.language not in languages:
return queryset.none()
queryset = queryset.translated(*languages).filter(
app_config=self.app_config)
featured_qs = featured_qs.translated(*languages).filter(
app_config=self.app_config)
exclude_featured = featured_qs.values_list(
'pk', flat=True)[:self.exclude_featured]
queryset = queryset.exclude(pk__in=list(exclude_featured))
return queryset[:self.latest_articles]

def __str__(self):
Expand Down

0 comments on commit 83a437a

Please sign in to comment.