1 from bpcms.models import Document, Folder
2 from django.conf import settings
3 from django.core.cache import cache
6 def content_menu(request):
7 menu_items = cache.get('bpcms_mainmenu')
10 items = Document.objects.filter(folder__isnull=True, islive__exact=True)
13 if item.slug != 'index':
17 'url': item.get_basic_url(),
20 folders = Folder.objects.filter(parent__isnull=True)
21 for folder in folders:
23 items = Document.objects.filter(folder__exact=folder, islive__exact=True, slug__exact='index')
28 'url': folder.get_basic_url(),
35 cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
36 cache.set('bpcms_mainmenu', menu_items, 3600)
39 'content_menu': menu_items,
42 def content_submenu(request):
43 # find where we are in the tree first
44 folderpath = request.path
45 folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath)
46 # right - that should be any prefix got rid of, now traverse the tree till
48 menu_items = cache.get('bpcms_contentmenu_%s' %(folderpath))
52 folderpath = folderpath.split('/')
53 for part in folderpath:
56 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
58 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
63 # We have the folder (in theory)
66 items = Document.objects.filter(folder__exact=folder, \
69 if item.slug != 'index':
73 'url': item.get_basic_url(),
77 folders = Folder.objects.filter(parent__exact=folder)
80 for folder in folders:
82 items = Document.objects.filter(folder__exact=folder, \
83 islive__exact=True, slug__exact='index')
88 'url': folder.get_basic_url(),
95 cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
97 cache.set('bpcms_contentmenu_%s' %(folderpath), menu_items)
100 'content_submenu': menu_items,
103 def content_breadcrumb(request):
104 if settings.BPCMS_ROOT == "/":
105 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': "Home"}]
107 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': settings.BPCMS_ROOT},]
108 # find where we are in the tree first
109 folderpath = request.path
110 folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath)
111 # right - that should be any prefix got rid of, now traverse the tree till
112 # we've got something
114 folderpath = folderpath.split('/')
115 for part in folderpath:
118 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
120 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
123 item = Document.objects.get(folder__exact=folder,
124 slug__exact=u'index', islive__exact=True)
125 breadcrumb.append({'url': folder.get_basic_url(),
126 'title': item.title})
128 breadcrumb.append({'url': folder.get_basic_url(),
129 'title': folder.title})
131 # must have hit the end of the tree, lets see if we can get an
135 item = Document.objects.get(folder__exact=folder, \
136 slug__exact=part, islive__exact=True)
138 item = Document.objects.get(folder__isnull=True, \
139 slug__exact=part, islive__exact=True)
140 breadcrumb.append({'url': item.get_basic_url(), 'title': item.title})
146 'content_breadcrumb': breadcrumb,