Fix menu behavior

This commit is contained in:
Iacopo Spalletti 2016-02-04 04:53:40 +01:00
parent 0f2abd8627
commit 1939ec7919
2 changed files with 21 additions and 15 deletions

View file

@ -51,7 +51,7 @@ Supported django CMS versions:
you have issues with tags, upgrade to latest version to have it fixed. 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 .. 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 .. warning:: Starting from version 0.5, this package does not declare dependency
on South anymore; please install it separately if using this on South anymore; please install it separately if using this
@ -235,11 +235,14 @@ Menu
``djangocms_blog`` provides support for django CMS menu framework. ``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 Is it possibile to configure per Apphook, whether the menu includes post and categories
(the default), only categorie, only posts or no item. (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 Templates
+++++++++ +++++++++
@ -374,14 +377,14 @@ Global Settings
(default: ``False``) (default: ``False``)
* BLOG_ADMIN_POST_FIELDSET_FILTER: Callable function to change(add or filter) * 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:: fields to fieldsets for admin post edit form; (default: ``False``). Function simple example::
def fieldset_filter_function(fsets, request, obj=None): def fieldset_filter_function(fsets, request, obj=None):
if request.user.groups.filter(name='Editor').exists(): if request.user.groups.filter(name='Editor').exists():
fsets[1][1]['fields'][0].append('author') # adding 'author' field if user is Editor fsets[1][1]['fields'][0].append('author') # adding 'author' field if user is Editor
return fsets return fsets
* BLOG_AVAILABLE_PERMALINK_STYLES: Choices of permalinks styles; * BLOG_AVAILABLE_PERMALINK_STYLES: Choices of permalinks styles;
* BLOG_PERMALINK_URLS: URLConf corresponding to * BLOG_PERMALINK_URLS: URLConf corresponding to
BLOG_AVAILABLE_PERMALINK_STYLES; BLOG_AVAILABLE_PERMALINK_STYLES;

View file

@ -52,20 +52,23 @@ class BlogCategoryMenu(CMSAttachMenu):
posts = posts.namespace(self.instance.application_namespace) posts = posts.namespace(self.instance.application_namespace)
posts = posts.active_translations(language).distinct() posts = posts.active_translations(language).distinct()
for post in posts: for post in posts:
post_id = None
if categories_menu: if categories_menu:
category = post.categories.first() category = post.categories.first()
parent = '%s-%s' % (category.__class__.__name__, category.pk) if category:
post_id = '%s-%s' % (post.__class__.__name__, post.pk), parent = '%s-%s' % (category.__class__.__name__, category.pk)
post_id = '%s-%s' % (post.__class__.__name__, post.pk),
else: else:
parent = None parent = None
post_id = '%s-%s' % (post.__class__.__name__, post.pk), post_id = '%s-%s' % (post.__class__.__name__, post.pk),
node = NavigationNode( if post_id:
post.get_title(), node = NavigationNode(
post.get_absolute_url(language), post.get_title(),
post_id, post.get_absolute_url(language),
parent post_id,
) parent
nodes.append(node) )
nodes.append(node)
return nodes return nodes