def setup(request): from django.conf import settings from django.contrib.sites.models import Site from navigation.utils import discover_sitemaps, refresh_all_menus discover_sitemaps() # disable autorefresh because will be publishing many pages settings.NAVIGATION_AUTO_REFRESH = False if Page.objects.count() == 0: _create_page("Home", None) _setup_life_tree() _setup_calendar() if Menu.objects.filter(name='Main Menu').count() == 0: menu = Menu(name='Main Menu') menu.site = Site.objects.get_current() menu.sitemap = Sitemap.objects.get(slug='cms-pages') menu.save() refresh_all_menus() return render(request, 'example/setup.html', {})
def get_navigation_breadcrumbs(current_path, menu=None, sitemap=None): # get or create menu for sitemap as needed if menu == None and sitemap: sitemap = Sitemap.current_objects.get(slug=sitemap) try: menu = Menu.current_objects.filter(sitemap=sitemap).get() except ObjectDoesNotExist: # create menu menu = Menu() menu.name = unicode(sitemap) menu.site = sitemap.site menu.sitemap = sitemap menu.save() from navigation.utils import refresh_menu_from_sitemap refresh_menu_from_sitemap(menu, sitemap) # create breadcrumbs from menu items = get_breadcrumbs_from_menu(current_path, menu) if not items: return None # add home item if needed from urlparse import urlparse top_url = urlparse(items[-1].url) if top_url.path != '' and top_url.path != '/': home_item = MenuItem() home_item.title = pgettext('navigation', 'Home') home_item.url = '/' items.append(home_item) items.reverse() return items