X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/blobdiff_plain/acedb5e82f30e6502e2801db9f8d64d879f44347..refs/heads/django-4.2:/sommitrealweird/bpcms/context_processors.py diff --git a/sommitrealweird/bpcms/context_processors.py b/sommitrealweird/bpcms/context_processors.py index c235c9b..1d254b1 100644 --- a/sommitrealweird/bpcms/context_processors.py +++ b/sommitrealweird/bpcms/context_processors.py @@ -4,6 +4,7 @@ from django.core.cache import cache import re def content_menu(request): + menu_items = cache.get('bpcms_mainmenu') if not menu_items: @@ -32,7 +33,7 @@ def content_menu(request): pass menu_items.sort( \ - cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower())) + key=lambda x: x['title'].lower()) cache.set('bpcms_mainmenu', menu_items, 3600) return { @@ -43,9 +44,16 @@ def content_submenu(request): # find where we are in the tree first folderpath = request.path folderpath = re.sub(u'^%s' %(settings.BPCMS_ROOT), '', folderpath) + # right - that should be any prefix got rid of, now traverse the tree till # we've got something - menu_items = cache.get('bpcms_contentmenu_%s' %(folderpath)) + try: + menu_items = cache.get('bpcms_contentmenu_%s' %(folderpath)) + except: + # fail on cache engine or bad key, ignore + return { + 'content_submenu': {}, + } if not menu_items: folder = None @@ -86,9 +94,9 @@ def content_submenu(request): ) menu_items.sort( \ - cmp=lambda x,y: cmp(x['title'].lower(), y['title'].lower())) + key=lambda x: x['title'].lower()) - cache.set('bpcms_contentmenu_%s' %(folderpath), menu_items) + cache.set('bpcms_contentmenu_%s' %("/".join(folderpath)), menu_items) return { 'content_submenu': menu_items,