Created
March 14, 2012 07:45
-
-
Save bebraw/2034914 to your computer and use it in GitHub Desktop.
Django navigation pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.translation import get_language, ugettext as _ | |
class Navi(list): | |
items = (_('Events'), _('Users'), ) | |
def __init__(self, cur_path): | |
lang = get_language() | |
first_part = '/' + cur_path.lstrip('/').split('/')[0] | |
def set_status(n): | |
if n['url'] == first_part: | |
n['status'] == 'active' | |
for i in self.items: | |
o = {'name': i, 'url': '/' + slugify(i)} | |
set_status(o) | |
self.append(o) | |
# remember to attach Navi() to your template context! | |
# ie. 'navi': Navi(request.path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment