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):
8 menu_items = cache.get('bpcms_mainmenu')
11 items = Document.objects.filter(folder__isnull=True, islive__exact=True)
14 if item.slug != 'index':
18 'url': item.get_absolute_url(),
21 folders = Folder.objects.filter(parent__isnull=True)
22 for folder in folders:
24 items = Document.objects.filter(folder__exact=folder, islive__exact=True, slug__exact='index')
29 'url': folder.get_absolute_url(),
36 cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
37 cache.set('bpcms_mainmenu', menu_items, 3600)
40 'content_menu': menu_items,
43 def content_submenu(request):
44 # find where we are in the tree first
45 folderpath = request.path
46 folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath)
47 # right - that should be any prefix got rid of, now traverse the tree till
49 menu_items = cache.get('bpcms_contentmenu_%s' %(folderpath))
53 folderpath = folderpath.split('/')
54 for part in folderpath:
57 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
59 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
64 # We have the folder (in theory)
67 items = Document.objects.filter(folder__exact=folder, \
70 if item.slug != 'index':
74 'url': item.get_absolute_url(),
77 folders = Folder.objects.filter(parent__exact=folder)
78 for folder in folders:
79 items = Document.objects.filter(folder__exact=folder, \
80 islive__exact=True, slug__exact='index')
85 'url': folder.get_absolute_url(),
90 cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
92 cache.set('bpcms_contentmenu_%s' %("/".join(folderpath)), menu_items)
95 'content_submenu': menu_items,
98 def content_breadcrumb(request):
99 if settings.BPCMS_ROOT == "/":
100 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': "Home"}]
102 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': settings.BPCMS_ROOT},]
103 # find where we are in the tree first
104 folderpath = request.path
105 folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath)
106 # right - that should be any prefix got rid of, now traverse the tree till
107 # we've got something
109 folderpath = folderpath.split('/')
110 for part in folderpath:
113 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
115 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
118 item = Document.objects.get(folder__exact=folder,
119 slug__exact=u'index', islive__exact=True)
120 breadcrumb.append({'url': folder.get_absolute_url(),
121 'title': item.title})
123 breadcrumb.append({'url': folder.get_absolute_url(),
124 'title': folder.title})
126 # must have hit the end of the tree, lets see if we can get an
130 item = Document.objects.get(folder__exact=folder, \
131 slug__exact=part, islive__exact=True)
133 item = Document.objects.get(folder__isnull=True, \
134 slug__exact=part, islive__exact=True)
135 breadcrumb.append({'url': item.get_absolute_url(), 'title': item.title})
141 'content_breadcrumb': breadcrumb,