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 key=lambda x: x['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)
48 # right - that should be any prefix got rid of, now traverse the tree till
51 menu_items = cache.get('bpcms_contentmenu_%s' %(folderpath))
53 # fail on cache engine or bad key, ignore
55 'content_submenu': {},
60 folderpath = folderpath.split('/')
61 for part in folderpath:
64 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
66 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
71 # We have the folder (in theory)
74 items = Document.objects.filter(folder__exact=folder, \
77 if item.slug != 'index':
81 'url': item.get_absolute_url(),
84 folders = Folder.objects.filter(parent__exact=folder)
85 for folder in folders:
86 items = Document.objects.filter(folder__exact=folder, \
87 islive__exact=True, slug__exact='index')
92 'url': folder.get_absolute_url(),
97 key=lambda x: x['title'].lower())
99 cache.set('bpcms_contentmenu_%s' %("/".join(folderpath)), menu_items)
102 'content_submenu': menu_items,
105 def content_breadcrumb(request):
106 if settings.BPCMS_ROOT == "/":
107 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': "Home"}]
109 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': settings.BPCMS_ROOT},]
110 # find where we are in the tree first
111 folderpath = request.path
112 folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath)
113 # right - that should be any prefix got rid of, now traverse the tree till
114 # we've got something
116 folderpath = folderpath.split('/')
117 for part in folderpath:
120 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
122 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
125 item = Document.objects.get(folder__exact=folder,
126 slug__exact=u'index', islive__exact=True)
127 breadcrumb.append({'url': folder.get_absolute_url(),
128 'title': item.title})
130 breadcrumb.append({'url': folder.get_absolute_url(),
131 'title': folder.title})
133 # must have hit the end of the tree, lets see if we can get an
137 item = Document.objects.get(folder__exact=folder, \
138 slug__exact=part, islive__exact=True)
140 item = Document.objects.get(folder__isnull=True, \
141 slug__exact=part, islive__exact=True)
142 breadcrumb.append({'url': item.get_absolute_url(), 'title': item.title})
148 'content_breadcrumb': breadcrumb,