move BlogCategoryMenu to a separate menu.py

This commit is contained in:
Tadas Dailyda 2015-02-14 14:23:35 +00:00
parent 2288d81659
commit 53a6beed00
2 changed files with 29 additions and 25 deletions

View file

@ -1,34 +1,10 @@
# -*- coding: utf-8 -*-
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from cms.menu_bases import CMSAttachMenu
from menus.base import NavigationNode
from menus.menu_pool import menu_pool
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _, get_language
from .models import BlogCategory
from .menu import BlogCategoryMenu
class BlogCategoryMenu(CMSAttachMenu):
name = _('Blog Category menu')
def get_nodes(self, request):
nodes = []
qs = BlogCategory.objects.translated(get_language())
qs = qs.order_by('parent_id', 'translations__name')
for category in qs:
kwargs = { 'category': category.slug }
node = NavigationNode(
category.name,
category.get_absolute_url(),
category.pk,
category.parent_id
)
nodes.append(node)
return nodes
menu_pool.register_menu(BlogCategoryMenu)
class BlogApp(CMSApp):
name = _('Blog')
urls = ['djangocms_blog.urls']

28
djangocms_blog/menu.py Normal file
View file

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from cms.menu_bases import CMSAttachMenu
from menus.base import NavigationNode
from menus.menu_pool import menu_pool
from django.utils.translation import ugettext_lazy as _, get_language
from .models import BlogCategory
class BlogCategoryMenu(CMSAttachMenu):
name = _('Blog Category menu')
def get_nodes(self, request):
nodes = []
qs = BlogCategory.objects.translated(get_language())
qs = qs.order_by('parent_id', 'translations__name')
for category in qs:
kwargs = { 'category': category.slug }
node = NavigationNode(
category.name,
category.get_absolute_url(),
category.pk,
category.parent_id
)
nodes.append(node)
return nodes
menu_pool.register_menu(BlogCategoryMenu)