]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/bpcms/context_processors.py
90b98cc902abe87be74ce7c1e05e4da2353666fc
[sommitrealweird.git] / sommitrealweird / bpcms / context_processors.py
1 from bpcms.models import Document, Folder
2 import operator
3
4 def content_menu(request):
5     items = Document.objects.filter(folder__isnull=True, islive__exact=True)
6     menu_items = []
7     for item in items:
8         if item.slug != 'index':
9             menu_items.append(
10                 {
11                     'title': item.title,
12                     'url': item.get_basic_url(),
13                 }
14             )
15     folders = Folder.objects.filter(parent__isnull=True)
16     for folder in folders:
17         try:
18             items = Document.objects.filter(folder__exact=folder, islive__exact=True, slug__exact='index')
19             item = items[0]
20             menu_items.append(
21                 {
22                     'title': item.title,
23                     'url': folder.get_basic_url(),
24                 }
25             )
26         except:
27             pass
28
29     menu_items.sort(cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
30
31     return {
32         'content_menu': menu_items,
33     }