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()))
98 'content_submenu': menu_items,
101 def content_breadcrumb(request):
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_basic_url(),
121 'title': item.title})
123 breadcrumb.append({'url': folder.get_basic_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_basic_url(), 'title': item.title})
141 'content_breadcrumb': breadcrumb,