Another Step in the Quest to clean up the code base.
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
# -*- encoding: UTF-8 -*-
|
||||
"""
|
||||
Created on 30.09.2011
|
||||
|
||||
@author: christian
|
||||
""" Django contextprocessor to have dynamicly generated menus in the templates.
|
||||
"""
|
||||
from django.core.cache import cache
|
||||
|
||||
@@ -10,6 +6,18 @@ from . import models
|
||||
|
||||
|
||||
def content_menus(request):
|
||||
""" Generate the menu tree and add these info to the template context.
|
||||
|
||||
The following variables will be added to the template context:
|
||||
- top_menu_items: QuerySet with all top level pages (children of the root)
|
||||
- current_top_page: Page Object of the top level page that is currently
|
||||
shown to the user, or it's childen are shown to the user.
|
||||
- current_path: the path part of the current URL,
|
||||
- current_page: the current Page object that is associated with this URL
|
||||
|
||||
:param request: a Django request object
|
||||
:return: a dict with the template variables mentioned above
|
||||
"""
|
||||
current_page = None
|
||||
current_top_page = None
|
||||
current_path = request.path_info[1:request.path_info.rfind('.')]
|
||||
@@ -36,7 +44,7 @@ def content_menus(request):
|
||||
all_pages = dict((path, page_id) for path, page_id in all_pages)
|
||||
cache.set('all_pages', all_pages, 360)
|
||||
|
||||
while len(current_path) > 0:
|
||||
while current_path:
|
||||
if current_path in all_pages:
|
||||
current_page = models.Page.objects.get(pk=all_pages[current_path])
|
||||
break
|
||||
@@ -45,5 +53,4 @@ def content_menus(request):
|
||||
return {'top_menu_items': top_level_pages,
|
||||
'current_top_page': current_top_page,
|
||||
'current_path': current_path,
|
||||
'current_page': current_page
|
||||
}
|
||||
'current_page': current_page}
|
||||
|
||||
Reference in New Issue
Block a user