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
49 folderpath = folderpath.split('/')
50 for part in folderpath:
53 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
55 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
60 # We have the folder (in theory)
63 items = Document.objects.filter(folder__exact=folder, \
66 if item.slug != 'index':
70 'url': item.get_basic_url(),
74 folders = Folder.objects.filter(parent__exact=folder)
77 for folder in folders:
79 items = Document.objects.filter(folder__exact=folder, \
80 islive__exact=True, slug__exact='index')
85 'url': folder.get_basic_url(),
92 cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
95 'content_submenu': menu_items,
98 def content_breadcrumb(request):
99 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': settings.BPCMS_ROOT},]
100 # find where we are in the tree first
101 folderpath = request.path
102 folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath)
103 # right - that should be any prefix got rid of, now traverse the tree till
104 # we've got something
106 folderpath = folderpath.split('/')
107 for part in folderpath:
110 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
112 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
115 item = Document.objects.get(folder__exact=folder,
116 slug__exact=u'index', islive__exact=True)
117 breadcrumb.append({'url': folder.get_basic_url(),
118 'title': item.title})
120 breadcrumb.append({'url': folder.get_basic_url(),
121 'title': folder.title})
123 # must have hit the end of the tree, lets see if we can get an
127 item = Document.objects.get(folder__exact=folder, \
128 slug__exact=part, islive__exact=True)
130 item = Document.objects.get(folder__isnull=True, \
131 slug__exact=part, islive__exact=True)
132 breadcrumb.append({'url': item.get_basic_url(), 'title': item.title})
138 'content_breadcrumb': breadcrumb,