예제 #1
0
def get_nodes(request):
    res = [] # result list
    n = NavigationNode(_('Sublevel'), reverse('sample-app-sublevel'))
    n2 = NavigationNode(_('Sublevel3'), reverse('sample-app-sublevel3'))
    n.childrens = [n2]
    res.append(n)
    n = NavigationNode(_('Sublevel 2'), reverse('sample-app-sublevel2'))
    res.append(n)
    return res
예제 #2
0
def get_nodes(request):
    res = [] # result list
    lang = request.LANGUAGE_CODE
    n = NavigationNode(_('Sublevel'), reverse('%s:sample-app-sublevel' % lang))
    n2 = NavigationNode(_('Sublevel3'), reverse('%s:sample-app-sublevel3' % lang))
    n.childrens = [n2]
    res.append(n)
    n = NavigationNode(_('Sublevel 2'), reverse('%s:sample-app-sublevel2' % lang))
    res.append(n)
    return res
예제 #3
0
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
            
예제 #4
0
파일: navigation.py 프로젝트: gipsy/docenko
def get_nodes(request):
    """ creates mptt style parent-child list for extending django-cms navigation (menu & breadcrumb); structured on photologue.urls """

    if cache.get('cmsplugin_photologue_get_nodes'):                 #if nav tree exists in cache, return it immediately
        return cache.get('cmsplugin_photologue_get_nodes')

    #the following is only executed if there is no cached nav tree
    res = []                                                        #create NavigationNode result list

    for q in gallery_args, photo_args:                              #get public Galleries & Photos
        if q.has_key('queryset'):                                   #use photologue defaults
            queryset = q['queryset']
            try:                                                    #get the name of the queryset's model
                model = q['queryset'][0].__class__.__name__.lower()
            except IndexError:                                      #abort if empty
                return res                                          #return empty navigation tree
        else:
            return res                                              #if no queryset, return empty navigation tree


        #create the base path of the URL ('gallery/' or 'photo/')
        base_node = NavigationNode(model, reverse('pl-%s-archive' % model,))
        base_node.childrens = []

        #create node for object_list view (photologue uses this view for pagination)
        #urlpattern to match: url(r'^photo/page/(?P<page>[0-9]+)/$', 'object_list', {'queryset': Photo.objects.filter(is_public=True), 'allow_empty': True, 'paginate_by': 20}, name='pl-photo-list'),
        #path example: request.META['PATH_INFO'] = u'/galleries/photo/page/2/'  or  u'/galleries/gallery/page/1/'
        try:
            #page_path gets the relevant parts of the path for paging
            #eg: '/mygalleries/gallery/page/1/' ->  ['gallery', 'page', '1']
            page_path = request.META['PATH_INFO'].split('/')[-4:-1]
            #execute only if page_path is a photologue paged url for this model
            assert len(page_path) == 3 and [model, 'page', str(int(page_path[2]))] == page_path
            #name the node with a string, reverse to the paged named url, and pass the page value from page_path
            pages_node = NavigationNode('page %s' % page_path[2], reverse('pl-%s-list' % model, kwargs=dict(page=page_path[2])))
            #modify url used in href, this doesn't work because NavigationNode uses the passed url for get_absolute_url
#            pages_node.get_absolute_url = lambda: reverse('pl-%s-list' % model, kwargs=dict(page=1))
            #attach the node to the main list
            base_node.childrens.append(pages_node)
        except:
            #fail silently if not applicable
            pass

        #create NavigationNodes for the queryset
        for item in queryset:

            years_done = []                                         #keeps track of published item years
            months_done = []
            days_done = []
            slug_done = []
            page_done = []

            #get the date for this query object; 'date_added' called 'date published' in photologue admin
            date = item.date_added

            if not date.year in years_done:                         #if this year is not in the years_done list
                years_done.append(date.year)                        #add it to years_done list
                #name the navigation node with the item's year, reverse to a named url, and pass the value captured by url regex
                year_node = NavigationNode(date.year, reverse('pl-%s-archive-year' % model, kwargs=dict(year=date.year)))
                year_node.childrens = []                            #create childrens sublist for this year
                months_done = []                                    #keeps track of published item months for this year
                base_node.childrens.append(year_node)                               #add this NavigationNode to the main list

            if not date.month in months_done:
                months_done.append(date.month)
                month_node = NavigationNode(date.strftime('%b').lower(), reverse('pl-%s-archive-month' % model, kwargs=dict(year=date.year, month=date.strftime('%b').lower())))
                month_node.get_menu_title = date.strftime('%m')     #use double int month name for menus
                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(date.day, reverse('pl-%s-archive-day' % model, kwargs=dict(year=date.year, month=date.strftime('%b').lower(), day=date.day)))
                day_node.childrens = []
                slug_done = []
                month_node.childrens.append(day_node)

            if not item.title_slug in slug_done:
                slug_done.append(item.title_slug)
                #one node child for the day node
                item_node = NavigationNode(item.title, reverse('pl-%s-detail' % model, kwargs=dict(year=date.year, month=date.strftime('%b').lower(), day=date.day, slug=item.title_slug)))
                day_node.childrens.append(item_node)
                #one node child for the base node
                item_node = NavigationNode(item.title, reverse('pl-%s' % model, kwargs=dict(slug=item.title_slug)))
                base_node.childrens.append(item_node)

        res.append(base_node)                                       #add base node ('gallery/' or 'photo/') to nav tree

    cache.set('cmsplugin_photologue_get_nodes', res)                #add nav tree to the django cache

    return res
예제 #5
0
    def recursive(nodes):
        for child in nodes: 
            try:
                ancestor = child.ancestor
            except:
                ancestor = False
            try:
                selected = child.selected
            except:
                selected = False
            
            if selected or ancestor:
            
                if 'news_and_events' in settings.INSTALLED_APPS and child in pages and child.entity.all()[0].auto_news_page:
                    menutitle = child.entity.all()[0].news_page_menu_title
                    new_node = NavigationNode(mark_safe(menutitle), child.entity.all()[0].get_absolute_url()  + "news-and-events/")
                    if request.path == new_node.get_absolute_url():
                        new_node.selected = True
                        child.selected=False
                    child.childrens.append(new_node)
                    
                if child in pages and child.entity.all()[0].auto_contacts_page:
                    menutitle = child.entity.all()[0].contacts_page_menu_title
                    new_node = NavigationNode(mark_safe(menutitle), child.entity.all()[0].get_absolute_url() + "contact/")
                    if request.path == new_node.get_absolute_url():
                        new_node.selected = True
                        child.selected=False
                    child.childrens.append(new_node)

                if 'vacancies_and_studentships' in settings.INSTALLED_APPS and child in pages and child.entity.all()[0].auto_vacancies_page:
                    menutitle = child.entity.all()[0].vacancies_page_menu_title
                    new_node = NavigationNode(mark_safe(menutitle), child.entity.all()[0].get_absolute_url()  + "vacancies-and-studentships/")
                    if request.path == new_node.get_absolute_url():
                        new_node.selected = True
                        child.selected=False
                    child.childrens.append(new_node)
                    
                if 'publications' in settings.INSTALLED_APPS and child in pages and child.entity.all()[0].auto_publications_page:
                    menutitle = child.entity.all()[0].publications_page_menu_title
                    new_node = NavigationNode(mark_safe(menutitle), child.entity.all()[0].get_absolute_url()  + "publications/")
                    if request.path == new_node.get_absolute_url():
                        new_node.selected = True
                        child.selected=False
                    child.childrens.append(new_node)
                    
            recursive(child.childrens)
    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