Skip to content

Commit

Permalink
Merge 0409a6f into 77da018
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky authored Aug 4, 2019
2 parents 77da018 + 0409a6f commit d2f8d8d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cms_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@ def setup():

if __name__ == '__main__':
run()

if __name__ == 'cms_helper':
# this is needed to run cms_helper in pycharm
setup()
5 changes: 4 additions & 1 deletion djangocms_blog/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def render(self, context, instance, placeholder):
qs = qs.filter(
models.Q(blog_posts__sites__isnull=True) | models.Q(blog_posts__sites=site.pk)
)
context['categories'] = qs.distinct()
categories = qs.distinct()
if instance.app_config and not instance.app_config.menu_empty_categories:
categories = qs.filter(blog_posts__isnull=False).distinct()
context['categories'] = categories
return context


Expand Down
13 changes: 13 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,16 @@ def test_blog_category_plugin(self):
with self.settings(SITE_ID=2):
context = plugin_class.render(context, plugin, ph)
self.assertEqual(list(context['categories']), [self.category_1, new_category])

empty_category = BlogCategory.objects.create(
name='empty 2', app_config=self.app_config_1
)
self.app_config_1.app_data.config.menu_empty_categories = False
self.app_config_1.save()
context = plugin_class.render(context, plugin, ph)
self.assertEqual(list(context['categories']), [self.category_1, new_category])

self.app_config_1.app_data.config.menu_empty_categories = True
self.app_config_1.save()
context = plugin_class.render(context, plugin, ph)
self.assertEqual(list(context['categories']), [self.category_1, new_category, empty_category])

0 comments on commit d2f8d8d

Please sign in to comment.