]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/content/context_processors.py
New menu code and reorg of URLs
[sommitrealweird.git] / sommitrealweird / content / context_processors.py
1 from content.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(folder__isnull=True)
16     for folder in folders:
17         try:
18             item = Document.objects.filter(folder__exact=folder, islive__exact=True, slug__exact='index')
19             menu_items.append(
20                 {
21                     'title': folder.title,
22                     'url': folder.get_basic_url(),
23                 }
24             )
25         except:
26             pass
27     
28     menu_items.sort(cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower()))
29     
30     return {
31         'content_menu': menu_items,
32     }