X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/e2e26ca7620b47ac804e99f1a3449f80473fdbf3..1e8f7eba9d079cfab82aaea20a214cae4c6f201a:/menu/helpers.py diff --git a/menu/helpers.py b/menu/helpers.py index 15d8646..3cf305b 100755 --- a/menu/helpers.py +++ b/menu/helpers.py @@ -1,21 +1,30 @@ +from django.utils.translation import get_language + + class MenuItem(object): html_id = None class InvalidMenuItem(BaseException): pass - def __init__(self, url, title, html_id=None, more_urls=None): + def __init__(self, url, title, html_id=None, more_urls=None, langs=None): self.url = url self.title = title self.html_id = html_id self.more_urls = more_urls or set() + self.langs = langs def is_valid(self): - return True + return not (self.langs and get_language() not in self.langs) def is_active(self, request, value): url = request.get_full_path() - return url == str(self.url) or url in set(str(url) for url in self.more_urls) + if url.startswith(str(self.url)): + return True + for other_url in self.more_urls: + if url.startswith(str(other_url)): + return True + return False def check_active(self, request, value): try: @@ -57,9 +66,11 @@ class ObjectMenuItem(MenuItem): return self.url or self.get_object().get_absolute_url() def is_valid(self): + if not super(ObjectMenuItem, self).is_valid(): + return False try: - obj = self.get_object() - except self.InvalidMenuItem, e: + self.get_object() + except self.InvalidMenuItem: return False return True