Mikhail Korobov avatar Mikhail Korobov committed 464a0fd

Attributes can be used instead of __init__ kwargs for menu items and dashboards initialization

Comments (0)

Files changed (2)

admin_tools/dashboard/dashboards.py

 
     .. image:: images/dashboard_example.png
     """
+
+    title = _('Dashboard')
+    template = 'admin_tools/dashboard/dashboard.html'
+    columns = 2
+    children = None
+
     class Media:
         css = ()
         js  = ()
 
     def __init__(self, **kwargs):
-        """
-        Dashboard constructor.
-        """
-        self.title = kwargs.get('title', _('Dashboard'))
-        self.template = kwargs.get('template', 'admin_tools/dashboard/dashboard.html')
-        self.columns = kwargs.get('columns', 2)
-        self.children = kwargs.get('children', [])
+        for key in kwargs:
+            setattr(self, key, kwargs[key])
+        self.children = self.children or []
 
     def init_with_context(self, context):
         """
     .. image:: images/dashboard_app_index_example.png
     """
     def __init__(self, app_title, models, **kwargs):
+        kwargs.update({'app_title': app_title, 'models': models})
         super(AppIndexDashboard, self).__init__(**kwargs)
-        self.app_title = app_title
-        self.models = models
 
     def get_app_model_classes(self):
         """
     And then set the ``ADMIN_TOOLS_APP_INDEX_DASHBOARD`` settings variable to
     point to your custom app index dashboard class.
     """
+
+    # we disable title because its redundant with the model list module
+    title = ''
+
     def __init__(self, *args, **kwargs):
         AppIndexDashboard.__init__(self, *args, **kwargs)
 
-        # we disable title because its redundant with the model list module
-        self.title = ''
-
         # append a model list module
         self.children.append(modules.ModelList(
             title=self.app_title,

admin_tools/menu/items.py

         the ``MenuItem`` class.
     """
 
+    title = 'Untitled menu item'
+    url = '#'
+    css_classes = None
+    accesskey = None
+    description = None
+    enabled = True
+    template = 'admin_tools/menu/item.html'
+    children = None
+
     def __init__(self, **kwargs):
-        """
-        ``MenuItem`` constructor.
-        """
-        self.title = kwargs.get('title', 'Untitled menu item')
-        self.url = kwargs.get('url', '#')
-        self.css_classes = kwargs.get('css_classes', [])
-        self.accesskey = kwargs.get('accesskey')
-        self.description = kwargs.get('description')
-        self.enabled = kwargs.get('enabled', True)
-        self.template = kwargs.get('template', 'admin_tools/menu/item.html')
-        self.children = kwargs.get('children', [])
+        for key in kwargs:
+            setattr(self, key, kwargs[key])
+        self.children = self.children or []
+        self.css_classes = self.css_classes or []
 
     def init_with_context(self, context):
         """
     def is_empty(self):
         """
         Helper method that returns ``True`` if the menu item is empty.
-        This method always returns ``False`` for basic items, but can return 
+        This method always returns ``False`` for basic items, but can return
         ``True`` if the item is an AppList.
         """
         return False
         """
         ``AppListMenuItem`` constructor.
         """
+        self.include_list = kwargs.pop('include_list', [])
+        self.exclude_list = kwargs.pop('exclude_list', [])
+        self.models = list(kwargs.pop('models', []))
+        self.exclude = list(kwargs.pop('exclude', []))
         super(AppList, self).__init__(**kwargs)
-        self.include_list = kwargs.get('include_list', [])
-        self.exclude_list = kwargs.get('exclude_list', [])
-        self.models = list(kwargs.get('models', []))
-        self.exclude = list(kwargs.get('exclude', []))
 
 
     def init_with_context(self, context):
 
     def is_empty(self):
         """
-        Helper method that returns ``True`` if the applist menu item has no 
+        Helper method that returns ``True`` if the applist menu item has no
         children.
 
         >>> from admin_tools.menu.items import MenuItem, AppList
                 self.children.append(items.Bookmarks(title='My bookmarks'))
 
     """
-
+    title = _('Bookmarks')
     def __init__(self, **kwargs):
         super(Bookmarks, self).__init__(**kwargs)
-        self.title = kwargs.get('title', _('Bookmarks'))
         if 'bookmark' not in self.css_classes:
             self.css_classes.append('bookmark')
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.