<s> from treenav . models import MenuItem <EOL> from django . core . cache import cache <EOL> def treenav_active ( request ) : <EOL> menus = cache . get ( '<STR_LIT>' ) <EOL> if not menus : <EOL> menus = MenuItem . objects . filter ( parent__isnull = True ) . all ( ) <EOL> cache . set ( '<STR_LIT>' , menus ) <EOL> treenav_active = { } <EOL> for menu in menus : <EOL> root = menu . to_tree ( ) <EOL> active_leaf = root . set_active ( request . META [ '<STR_LIT>' ] ) <EOL> if active_leaf : <EOL> treenav_active [ menu . slug ] = active_leaf . get_active_items ( ) <EOL> return { '<STR_LIT>' : treenav_active } </s>
