Commits

Horst Gutmann committed 37deb5f

Initial work on menu integration using old navigation module

Comments (0)

Files changed (3)

cmsplugin_news/cms_app.py

 from cms.app_base import CMSApp
 from cms.apphook_pool import apphook_pool
 
+from .menu import NewsItemMenu
+
 
 class NewsAppHook(CMSApp):
     name = _('News App')
     urls = ['cmsplugin_news.urls']
+    menus = [NewsItemMenu]
 
 
 apphook_pool.register(NewsAppHook)

cmsplugin_news/menu.py

+"""
+This module hooks into django-cms' menu system by providing a clear menu
+hierarchy for every news item.
+"""
+from django.utils.translation import ugettext_lazy as _
+
+from menus.menu_pool import menu_pool
+from cms.menu_bases import CMSAttachMenu
+
+from . import navigation
+
+
+class NewsItemMenu(CMSAttachMenu):
+    name = _("News menu")
+
+    def get_nodes(self, request):
+        return navigation.get_nodes(request)
+
+
+menu_pool.register_menu(NewsItemMenu)

cmsplugin_news/navigation.py

 from datetime import datetime
+import logging
 from django.core.urlresolvers import reverse
 
-from cms.utils.navigation import NavigationNode
+from menus.base import NavigationNode
 
 from cmsplugin_news.models import News
 
 
+logger = logging.getLogger(__name__)
+
+
 def get_nodes(request):
+    logger.debug("Rebuilding news menu")
     res = []
 
     items = News.published.all()
 
         if not date.year in years_done:
             years_done.append(date.year)
-            year_node = NavigationNode(date.year, reverse('news_archive_year', kwargs=dict(year=date.year)))
+            year_node = NavigationNode(date.year,
+                reverse('news_archive_year', kwargs=dict(year=date.year)),
+                'newsitem-year-%d' % (date.year,))
             year_node.childrens = []
             months_done = []
             res.append(year_node)
             month_node = NavigationNode(datetime.strftime(date, '%B'),
                                 reverse('news_archive_month', kwargs=dict(
                                     year=date.year,
-                                    month=datetime.strftime(date, '%m'))))
+                                    month=datetime.strftime(date, '%m'))),
+                                'newsitem-month-%d.%d' % (date.year, date.month))
             month_node.childrens = []
             days_done = []
             year_node.childrens.append(month_node)
         if not date.day in days_done:
             days_done.append(date.day)
             day_node = NavigationNode(datetime.strftime(date, '%d'),
-                                reverse('news_archive_day', kwargs=dict(
-                                    year=date.year,
-                                    month=datetime.strftime(date, '%m'),
-                                    day=datetime.strftime(date, '%d'))))
+                reverse('news_archive_day', kwargs=dict(
+                    year=date.year,
+                    month=datetime.strftime(date, '%m'),
+                    day=datetime.strftime(date, '%d'))),
+                'newsitem-day-%d.%d.%d' % (date.year, date.month, date.day)
+                )
             day_node.childrens = []
             slug_done = []
             month_node.childrens.append(day_node)
 
         if not item.slug in slug_done:
             slug_done.append(item.slug)
-            item_node = NavigationNode(item.title, item.get_absolute_url())
+            item_node = NavigationNode(item.title, item.get_absolute_url(),
+                'newsitem-pk-%s' % (str(item.pk),))
             item_node.childrens = []
             day_node.childrens.append(item_node)