1 from bpcms.models import Document, Folder
2 from django.conf import settings
5 def content_menu(request):
6 items = Document.objects.filter(folder__isnull=True, islive__exact=True)
9 if item.slug != 'index':
13 'url': item.get_basic_url(),
16 folders = Folder.objects.filter(parent__isnull=True)
17 for folder in folders:
19 items = Document.objects.filter(folder__exact=folder, islive__exact=True, slug__exact='index')
24 'url': folder.get_basic_url(),
31 cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
34 'content_menu': menu_items,
37 def content_submenu(request):
38 # find where we are in the tree first
39 folderpath = request.path
40 folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath)
41 # right - that should be any prefix got rid of, now traverse the tree till
44 folderpath = folderpath.split('/')
45 for part in folderpath:
48 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
50 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
55 # We have the folder (in theory)
58 items = Document.objects.filter(folder__exact=folder, \
61 if item.slug != 'index':
65 'url': item.get_basic_url(),
69 folders = Folder.objects.filter(parent__exact=folder)
72 for folder in folders:
74 items = Document.objects.filter(folder__exact=folder, \
75 islive__exact=True, slug__exact='index')
80 'url': folder.get_basic_url(),
87 cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
90 'content_submenu': menu_items,
93 def content_breadcrumb(request):
94 breadcrumb = [{'url': settings.BPCMS_ROOT, 'title': settings.BPCMS_ROOT},]
95 # find where we are in the tree first
96 folderpath = request.path
97 folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath)
98 # right - that should be any prefix got rid of, now traverse the tree till
101 folderpath = folderpath.split('/')
102 for part in folderpath:
105 f = Folder.objects.get(parent__exact=folder, slug__exact=part)
107 f = Folder.objects.get(parent__isnull=True, slug__exact=part)
110 item = Document.objects.get(folder__exact=folder,
111 slug__exact=u'index', islive__exact=True)
112 breadcrumb.append({'url': folder.get_basic_url(),
113 'title': item.title})
115 breadcrumb.append({'url': folder.get_basic_url(),
116 'title': folder.title})
118 # must have hit the end of the tree, lets see if we can get an
122 item = Document.objects.get(folder__exact=folder, \
123 slug__exact=part, islive__exact=True)
125 item = Document.objects.get(folder__isnull=True, \
126 slug__exact=part, islive__exact=True)
127 breadcrumb.append({'url': item.get_basic_url(), 'title': item.title})
133 'content_breadcrumb': breadcrumb,