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_absolute_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_absolute_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_absolute_url(),
76 folders = Folder.objects.filter(parent__exact=folder)
77 for folder in folders:
78 items = Document.objects.filter(folder__exact=folder, \
79 islive__exact=True, slug__exact='index')
84 'url': folder.get_absolute_url(),
89 cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
91 cache.set('bpcms_contentmenu_%s' %(folderpath), menu_items)
94 'content_submenu': menu_items,
97 def content_breadcrumb(request):
98 if settings.BPCMS_ROOT == "/":
99 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': "Home"}]
101 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': settings.BPCMS_ROOT},]
102 # find where we are in the tree first
103 folderpath = request.path
104 folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath)
105 # right - that should be any prefix got rid of, now traverse the tree till
106 # we've got something
108 folderpath = folderpath.split('/')
109 for part in folderpath:
112 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
114 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
117 item = Document.objects.get(folder__exact=folder,
118 slug__exact=u'index', islive__exact=True)
119 breadcrumb.append({'url': folder.get_absolute_url(),
120 'title': item.title})
122 breadcrumb.append({'url': folder.get_absolute_url(),
123 'title': folder.title})
125 # must have hit the end of the tree, lets see if we can get an
129 item = Document.objects.get(folder__exact=folder, \
130 slug__exact=part, islive__exact=True)
132 item = Document.objects.get(folder__isnull=True, \
133 slug__exact=part, islive__exact=True)
134 breadcrumb.append({'url': item.get_absolute_url(), 'title': item.title})
140 'content_breadcrumb': breadcrumb,