Source

cmsplugin-advancednews / cmsplugin_advancednews / navigation.py

from datetime import datetime
from django.core.urlresolvers import reverse

from menus.base import NavigationNode
from cmsplugin_news.models import News

def get_nodes(request):
    res = []
    
    items = News.published.all()
    
    years_done = []
    months_done = []
    days_done = []
    slug_done = []
    
    for item in items:
        date = item.pub_date
        
        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.childrens = []
            months_done = []
            res.append(year_node)
        
        if not date.month in months_done:
            months_done.append(date.month)
            month_node = NavigationNode(datetime.strftime(date, '%B'), 
                                        reverse('news_archive_month', kwargs=dict(
                                            year=date.year, 
                                            month=datetime.strftime(date, '%m'))))
            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'))))
            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.childrens = []
            day_node.childrens.append(item_node)
            
    return res
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.