Commits

Mikhail Korobov  committed f3b5805

Positional arguments for menu items

  • Participants
  • Parent commits 9ce0709

Comments (0)

Files changed (2)

File admin_tools/menu/items.py

     template = 'admin_tools/menu/item.html'
     children = None
 
-    def __init__(self, **kwargs):
+    def __init__(self, title=None, url=None, **kwargs):
+
+        if title is not None:
+            self.title = title
+
+        if url is not None:
+            self.url = url
+
         for key in kwargs:
             if hasattr(self.__class__, key):
                 setattr(self, key, kwargs[key])
         displayed in the menu item.
     """
 
-    def __init__(self, **kwargs):
+    def __init__(self, title=None, url=None, **kwargs):
         """
         ``AppListMenuItem`` constructor.
         """
         self.exclude_list = kwargs.pop('exclude_list', [])
         self.models = list(kwargs.pop('models', []))
         self.exclude = list(kwargs.pop('exclude', []))
-        super(AppList, self).__init__(**kwargs)
+        super(AppList, self).__init__(title, url, **kwargs)
 
 
     def init_with_context(self, context):
         class MyMenu(Menu):
             def __init__(self, **kwargs):
                 super(MyMenu, self).__init__(**kwargs)
-                self.children.append(items.Bookmarks(title='My bookmarks'))
+                self.children.append(items.Bookmarks('My bookmarks'))
 
     """
     title = _('Bookmarks')
 
-    def __init__(self, **kwargs):
-        super(Bookmarks, self).__init__(**kwargs)
+    def __init__(self, title=None, **kwargs):
+        super(Bookmarks, self).__init__(title, **kwargs)
         if 'bookmark' not in self.css_classes:
             self.css_classes.append('bookmark')
 
         documentation from :class:`~admin_tools.menu.items.MenuItem` class.
         """
         from admin_tools.menu.models import Bookmark
+
         for b in Bookmark.objects.filter(user=context['request'].user):
-            self.children.append(MenuItem(
-                url=b.url,
-                title=mark_safe(b.title)
-            ))
+            self.children.append(MenuItem(b.url, mark_safe(b.title)))
+
         if not len(self.children):
             self.enabled = False
 

File admin_tools/menu/menus.py

             def __init__(self, **kwargs):
                 super(MyMenu, self).__init__(**kwargs)
                 self.children.append(
-                    items.MenuItem(title='Home', url=reverse('admin:index'))
+                    items.MenuItem('Home', reverse('admin:index'))
                 )
                 self.children.append(
-                    items.AppList(title='Applications')
+                    items.AppList('Applications')
                 )
                 self.children.append(
                     items.MenuItem(
         super(DefaultMenu, self).__init__(**kwargs)
 
         self.children += [
-            items.MenuItem(
-                title=_('Dashboard'),
-                url=reverse('admin:index')
-            ),
+            items.MenuItem(_('Dashboard'), reverse('admin:index')),
             items.Bookmarks(),
             items.AppList(
-                title=_('Applications'),
+                _('Applications'),
                 exclude_list=('django.contrib',)
             ),
             items.AppList(
-                title=_('Administration'),
+                _('Administration'),
                 include_list=('django.contrib',)
             )
         ]