Add option to exclude empty categories from menu
This commit is contained in:
parent
8b248e7b0f
commit
c1edba9772
4 changed files with 55 additions and 21 deletions
|
|
@ -70,6 +70,8 @@ class MenuTest(BaseTest):
|
|||
posts = self.get_posts()
|
||||
|
||||
cats_url = {}
|
||||
cats_with_post_url = {}
|
||||
cats_without_post_url = {}
|
||||
posts_url = {}
|
||||
|
||||
languages = ('en', 'it')
|
||||
|
|
@ -77,6 +79,8 @@ class MenuTest(BaseTest):
|
|||
for lang in languages:
|
||||
with smart_override(lang):
|
||||
cats_url[lang] = set([cat.get_absolute_url() for cat in self.cats if cat.has_translation(lang)])
|
||||
cats_with_post_url[lang] = set([cat.get_absolute_url() for cat in self.cats if cat.has_translation(lang) and cat.blog_posts.published().exists()])
|
||||
cats_without_post_url[lang] = cats_url[lang].difference(cats_with_post_url[lang])
|
||||
posts_url[lang] = set([post.get_absolute_url(lang) for post in posts if post.has_translation(lang) and post.app_config == self.app_config_1])
|
||||
|
||||
# No item in the menu
|
||||
|
|
@ -127,6 +131,27 @@ class MenuTest(BaseTest):
|
|||
self.assertTrue(cats_url[lang].issubset(nodes_url))
|
||||
self.assertTrue(posts_url[lang].issubset(nodes_url))
|
||||
|
||||
# Both types in the menu
|
||||
self.app_config_1.app_data.config.menu_empty_categories = False
|
||||
self.app_config_1.save()
|
||||
self.app_config_2.app_data.config.menu_empty_categories = False
|
||||
self.app_config_2.save()
|
||||
cache.clear()
|
||||
for lang in languages:
|
||||
request = self.get_page_request(None, self.user, r'/%s/page-two/' % lang)
|
||||
with smart_override(lang):
|
||||
nodes = menu_pool.get_nodes(request)
|
||||
nodes_url = set([node.url for node in nodes])
|
||||
self.assertTrue(cats_with_post_url[lang].issubset(nodes_url))
|
||||
self.assertFalse(cats_without_post_url[lang].intersection(nodes_url))
|
||||
self.assertTrue(posts_url[lang].issubset(nodes_url))
|
||||
# Both types in the menu
|
||||
self.app_config_1.app_data.config.menu_empty_categories = True
|
||||
self.app_config_1.save()
|
||||
self.app_config_2.app_data.config.menu_empty_categories = True
|
||||
self.app_config_2.save()
|
||||
cache.clear()
|
||||
|
||||
def test_modifier(self):
|
||||
"""
|
||||
Tests if correct category is selected in the menu
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue