update menu
authorJan Szejko <janek37@gmail.com>
Mon, 29 Aug 2016 15:25:00 +0000 (17:25 +0200)
committerJan Szejko <janek37@gmail.com>
Mon, 29 Aug 2016 15:25:00 +0000 (17:25 +0200)
menu/helpers.py
prawokultury/menu_items.py

index 33e90b7..3cf305b 100755 (executable)
@@ -1,17 +1,21 @@
+from django.utils.translation import get_language
+
+
 class MenuItem(object):
     html_id = None
 
     class InvalidMenuItem(BaseException):
         pass
 
 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.url = url
         self.title = title
         self.html_id = html_id
         self.more_urls = more_urls or set()
+        self.langs = langs
 
     def is_valid(self):
 
     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()
 
     def is_active(self, request, value):
         url = request.get_full_path()
@@ -62,9 +66,11 @@ class ObjectMenuItem(MenuItem):
         return self.url or self.get_object().get_absolute_url()
 
     def is_valid(self):
         return self.url or self.get_object().get_absolute_url()
 
     def is_valid(self):
+        if not super(ObjectMenuItem, self).is_valid():
+            return False
         try:
         try:
-            obj = self.get_object()
-        except self.InvalidMenuItem, e:
+            self.get_object()
+        except self.InvalidMenuItem:
             return False
         return True
 
             return False
         return True
 
index 1da9c69..581455c 100644 (file)
@@ -5,26 +5,19 @@ from django.core.urlresolvers import reverse_lazy
 from django.utils.translation import ugettext_lazy as _
 
 
 from django.utils.translation import ugettext_lazy as _
 
 
-ITEMS = []
-
-ITEMS.append(ObjectMenuItem(
-    obj_get=lambda:Entry.published_objects.get(slug_pl='o-nas')
-))
-
-ITEMS.append(ModelMenuItem(Entry, reverse_lazy('migdal_entry_list_publications'),
-        field_lookups={'type': 'publications'}, title=_('Publications')))
-
-ITEMS.append(MenuItem(reverse_lazy('events'), _('Events')))
-
-ITEMS.append(ObjectMenuItem(
-    obj_get=lambda:Category.objects.get(slug_pl='stanowisko'),
-    rev_lookups={Entry: 'categories'},
-    title=_('Positions')
-))
-
-ITEMS.append(MenuItem(reverse_lazy('questions'), _('First aid')))
-
-ITEMS.append(ObjectMenuItem(
-    obj_get=lambda:Entry.published_objects.get(slug_pl='pierwsza-pomoc'),
-    title=_('Guide')
-))
+ITEMS = [
+    ObjectMenuItem(obj_get=lambda: Entry.published_objects.get(slug_pl='o-nas')),
+    ModelMenuItem(Entry, reverse_lazy('migdal_entry_list_publications'),
+                  field_lookups={'type': 'publications'}, title=_('Publications')),
+    MenuItem(reverse_lazy('events'), _('Events'), langs=['en']),
+    MenuItem('/kurs/', u'Kurs dla uczelni', langs=['pl']),
+    ObjectMenuItem(
+        obj_get=lambda: Category.objects.get(slug_pl='stanowisko'),
+        rev_lookups={Entry: 'categories'},
+        title=_('Positions')),
+    MenuItem(
+        reverse_lazy('questions'), _('First aid')),
+    ObjectMenuItem(
+        obj_get=lambda: Entry.published_objects.get(slug_pl='pierwsza-pomoc'),
+        title=_('Guide')),
+]