Merge pull request #195 from nephila/feature/non_required_categories
Fix menu behavior
This commit is contained in:
commit
ae2b4a1f6f
5 changed files with 48 additions and 27 deletions
3
.checkignore
Normal file
3
.checkignore
Normal file
|
@ -0,0 +1,3 @@
|
|||
tests/*
|
||||
docs/*
|
||||
djangocms_blog/south_migrations/*
|
15
README.rst
15
README.rst
|
@ -51,7 +51,7 @@ Supported django CMS versions:
|
|||
you have issues with tags, upgrade to latest version to have it fixed.
|
||||
|
||||
.. warning:: When upgrading to version 0.6, check that every post as an attached
|
||||
category, or select a menu without categories.
|
||||
category, or select a menu without categories.
|
||||
|
||||
.. warning:: Starting from version 0.5, this package does not declare dependency
|
||||
on South anymore; please install it separately if using this
|
||||
|
@ -235,11 +235,14 @@ Menu
|
|||
|
||||
``djangocms_blog`` provides support for django CMS menu framework.
|
||||
|
||||
By default all the categories and posts are added to the menu, in a hierarcical structure.
|
||||
By default all the categories and posts are added to the menu, in a hierarchical structure.
|
||||
|
||||
Is it possibile to configure per Apphook, whether the menu includes post and categories
|
||||
(the default), only categorie, only posts or no item.
|
||||
|
||||
If "post and categories" or "only categories" are set, all the posts not associated with a
|
||||
category are not added to the menu.
|
||||
|
||||
Templates
|
||||
+++++++++
|
||||
|
||||
|
@ -374,14 +377,14 @@ Global Settings
|
|||
(default: ``False``)
|
||||
* BLOG_ADMIN_POST_FIELDSET_FILTER: Callable function to change(add or filter)
|
||||
fields to fieldsets for admin post edit form; (default: ``False``). Function simple example::
|
||||
|
||||
|
||||
|
||||
|
||||
def fieldset_filter_function(fsets, request, obj=None):
|
||||
if request.user.groups.filter(name='Editor').exists():
|
||||
fsets[1][1]['fields'][0].append('author') # adding 'author' field if user is Editor
|
||||
return fsets
|
||||
|
||||
|
||||
|
||||
|
||||
* BLOG_AVAILABLE_PERMALINK_STYLES: Choices of permalinks styles;
|
||||
* BLOG_PERMALINK_URLS: URLConf corresponding to
|
||||
BLOG_AVAILABLE_PERMALINK_STYLES;
|
||||
|
|
|
@ -69,7 +69,7 @@ HELPER_SETTINGS = dict(
|
|||
{'code': 'en'},
|
||||
),
|
||||
'default': {
|
||||
'fallback': 'en',
|
||||
'fallbacks': ['en'],
|
||||
'hide_untranslated': False,
|
||||
}
|
||||
},
|
||||
|
|
|
@ -52,20 +52,23 @@ class BlogCategoryMenu(CMSAttachMenu):
|
|||
posts = posts.namespace(self.instance.application_namespace)
|
||||
posts = posts.active_translations(language).distinct()
|
||||
for post in posts:
|
||||
post_id = None
|
||||
parent = None
|
||||
if categories_menu:
|
||||
category = post.categories.first()
|
||||
parent = '%s-%s' % (category.__class__.__name__, category.pk)
|
||||
post_id = '%s-%s' % (post.__class__.__name__, post.pk),
|
||||
if category:
|
||||
parent = '%s-%s' % (category.__class__.__name__, category.pk)
|
||||
post_id = '%s-%s' % (post.__class__.__name__, post.pk),
|
||||
else:
|
||||
parent = None
|
||||
post_id = '%s-%s' % (post.__class__.__name__, post.pk),
|
||||
node = NavigationNode(
|
||||
post.get_title(),
|
||||
post.get_absolute_url(language),
|
||||
post_id,
|
||||
parent
|
||||
)
|
||||
nodes.append(node)
|
||||
if post_id:
|
||||
node = NavigationNode(
|
||||
post.get_title(),
|
||||
post.get_absolute_url(language),
|
||||
post_id,
|
||||
parent
|
||||
)
|
||||
nodes.append(node)
|
||||
|
||||
return nodes
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
|
||||
from aldryn_apphooks_config.utils import get_app_instance
|
||||
from django.core.cache import cache
|
||||
from django.utils.translation import activate
|
||||
from django.utils.translation import activate, override
|
||||
from menus.menu_pool import menu_pool
|
||||
from parler.utils.context import smart_override, switch_language
|
||||
|
||||
|
@ -32,22 +32,34 @@ class MenuTest(BaseTest):
|
|||
# All cms menu modifiers should be removed from menu_pool.modifiers
|
||||
# so that they do not interfere with our menu nodes
|
||||
menu_pool.modifiers = [m for m in menu_pool.modifiers if m.__module__.startswith('djangocms_blog')]
|
||||
cache.clear()
|
||||
|
||||
def test_menu_nodes(self):
|
||||
"""
|
||||
Tests if all categories are present in the menu
|
||||
"""
|
||||
self.get_posts()
|
||||
self.get_pages()
|
||||
posts = self.get_posts()
|
||||
pages = self.get_pages()
|
||||
self.reload_urlconf()
|
||||
|
||||
for lang in ('en', 'it'):
|
||||
request = self.get_page_request(None, self.user, r'/%s/page-two/' % lang)
|
||||
with smart_override(lang):
|
||||
nodes = menu_pool.get_nodes(request, namespace='BlogCategoryMenu')
|
||||
request = self.get_page_request(pages[1], self.user, pages[1].get_absolute_url(lang))
|
||||
nodes = menu_pool.get_nodes(request)
|
||||
nodes_url = set([node.url for node in nodes])
|
||||
cats_url = set([cat.get_absolute_url() for cat in self.cats if cat.has_translation(lang)])
|
||||
self.assertTrue(cats_url.issubset(nodes_url))
|
||||
|
||||
cache.clear()
|
||||
posts[0].categories.clear()
|
||||
for lang in ('en', 'it'):
|
||||
with smart_override(lang):
|
||||
request = self.get_page_request(pages[1], self.user, pages[1].get_absolute_url(lang))
|
||||
nodes = menu_pool.get_nodes(request)
|
||||
nodes_url = set([node.url for node in nodes])
|
||||
self.assertFalse(posts[0].get_absolute_url(lang) in nodes_url)
|
||||
self.assertTrue(posts[1].get_absolute_url(lang) in nodes_url)
|
||||
|
||||
def test_menu_options(self):
|
||||
"""
|
||||
Tests menu structure based on menu_structure configuration
|
||||
|
@ -72,7 +84,7 @@ class MenuTest(BaseTest):
|
|||
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, namespace='BlogCategoryMenu')
|
||||
nodes = menu_pool.get_nodes(request)
|
||||
nodes_url = set([node.url for node in nodes])
|
||||
self.assertFalse(cats_url[lang].issubset(nodes_url))
|
||||
self.assertFalse(posts_url[lang].issubset(nodes_url))
|
||||
|
@ -84,7 +96,7 @@ class MenuTest(BaseTest):
|
|||
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, namespace='BlogCategoryMenu')
|
||||
nodes = menu_pool.get_nodes(request)
|
||||
nodes_url = set([node.url for node in nodes])
|
||||
self.assertFalse(cats_url[lang].issubset(nodes_url))
|
||||
self.assertTrue(posts_url[lang].issubset(nodes_url))
|
||||
|
@ -96,7 +108,7 @@ class MenuTest(BaseTest):
|
|||
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, namespace='BlogCategoryMenu')
|
||||
nodes = menu_pool.get_nodes(request)
|
||||
nodes_url = set([node.url for node in nodes])
|
||||
self.assertTrue(cats_url[lang].issubset(nodes_url))
|
||||
self.assertFalse(posts_url[lang].issubset(nodes_url))
|
||||
|
@ -108,7 +120,7 @@ class MenuTest(BaseTest):
|
|||
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, namespace='BlogCategoryMenu')
|
||||
nodes = menu_pool.get_nodes(request)
|
||||
nodes_url = set([node.url for node in nodes])
|
||||
self.assertTrue(cats_url[lang].issubset(nodes_url))
|
||||
self.assertTrue(posts_url[lang].issubset(nodes_url))
|
||||
|
@ -137,7 +149,7 @@ class MenuTest(BaseTest):
|
|||
view_obj.kwargs = {kwarg: obj.slug}
|
||||
view_obj.get(request)
|
||||
# check if selected menu node points to cat
|
||||
nodes = menu_pool.get_nodes(request, namespace='BlogCategoryMenu')
|
||||
nodes = menu_pool.get_nodes(request)
|
||||
found = False
|
||||
for node in nodes:
|
||||
if node.selected:
|
||||
|
|
Loading…
Reference in a new issue