Mikhail Korobov avatar Mikhail Korobov committed dcd033d

Attributes can be used instead of __init__ kwargs for dashboard module initialization

Comments (0)

Files changed (1)

admin_tools/dashboard/modules.py

         The template to use to render the module.
         Default value: 'admin_tools/dashboard/module.html'.
     """
+
+    template = 'admin_tools/dashboard/module.html'
+    enabled = True
+    draggable = True
+    collapsible = True
+    deletable = True
+    show_title = True
+    title = ''
+    title_url = None
+    css_classes = None
+    pre_content = None
+    post_content = None
+    children = None
+
     def __init__(self, **kwargs):
-        self.enabled = kwargs.get('enabled', True)
-        self.draggable = kwargs.get('draggable', True)
-        self.collapsible = kwargs.get('collapsible', True)
-        self.deletable = kwargs.get('deletable', True)
-        self.show_title = kwargs.get('show_title', True)
-        self.title = kwargs.get('title', '')
-        self.title_url = kwargs.get('title_url', None)
-        self.css_classes = kwargs.get('css_classes', [])
-        self.pre_content = kwargs.get('pre_content')
-        self.post_content = kwargs.get('post_content')
-        self.template = kwargs.get('template', 'admin_tools/dashboard/module.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):
         """
         of the following values: 'tabs' (default), 'accordion' or 'stacked'.
 
     Here's an example of modules group::
-        
+
         from admin_tools.dashboard import modules, Dashboard
 
         class MyDashboard(Dashboard):
     .. image:: images/dashboard_module_group.png
     """
 
-    def __init__(self, **kwargs):
-        super(Group, self).__init__(**kwargs)
-        self.template = kwargs.get('template',
-                                   'admin_tools/dashboard/modules/group.html')
-        self.display = kwargs.get('display', 'tabs')
-        
+    template = 'admin_tools/dashboard/modules/group.html'
+    display = 'tabs'
+
     def init_with_context(self, context):
         for module in self.children:
-            # to simplify the whole stuff, modules have some limitations, 
+            # to simplify the whole stuff, modules have some limitations,
             # they cannot be dragged, collapsed or closed
             module.collapsible = False
             module.draggable = False
     .. image:: images/linklist_dashboard_module.png
     """
 
-    def __init__(self, **kwargs):
-        super(LinkList, self).__init__(**kwargs)
-        self.title = kwargs.get('title', _('Links'))
-        self.template = kwargs.get('template',
-                                   'admin_tools/dashboard/modules/link_list.html')
-        self.layout = kwargs.get('layout', 'stacked')
+    title = _('Links')
+    template = 'admin_tools/dashboard/modules/link_list.html'
+    layout = 'stacked'
 
 
 class AppList(DashboardModule, AppListElementMixin):
         the django.contrib.auth.Group model line will not be displayed.
     """
 
+    title = _('Applications')
+    template = 'admin_tools/dashboard/modules/app_list.html'
+    models = None
+    exclude = None
+    include_list = None
+    exclude_list = None
+
     def __init__(self, **kwargs):
+        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.title = kwargs.get('title', _('Applications'))
-        self.template = kwargs.get('template',
-                                   'admin_tools/dashboard/modules/app_list.html')
-        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):
         items = self._visible_models(context['request'])
         the django.contrib.auth.Group model line will not be displayed.
     """
 
+    template = 'admin_tools/dashboard/modules/model_list.html'
+
     def __init__(self, **kwargs):
+        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(ModelList, self).__init__(**kwargs)
-        self.title = kwargs.get('title', '')
-        self.template = kwargs.get('template',
-                                   'admin_tools/dashboard/modules/model_list.html')
-        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):
         items = self._visible_models(context['request'])
 
     .. image:: images/recentactions_dashboard_module.png
     """
+    title = _('Recent Actions')
+    template = 'admin_tools/dashboard/modules/recent_actions.html'
+    limit = 10
 
     def __init__(self, **kwargs):
+        self.include_list = kwargs.pop('include_list', [])
+        self.exclude_list = kwargs.pop('exclude_list', [])
         super(RecentActions, self).__init__(**kwargs)
-        self.title = kwargs.get('title', _('Recent Actions'))
-        self.template = kwargs.get('template',
-                                   'admin_tools/dashboard/modules/recent_actions.html')
-        self.include_list = kwargs.get('include_list', [])
-        self.exclude_list = kwargs.get('exclude_list', [])
-        self.limit = kwargs.get('limit', 10)
 
     def init_with_context(self, context):
         from django.db.models import Q
 
     .. image:: images/feed_dashboard_module.png
     """
-    def __init__(self, **kwargs):
-        super(Feed, self).__init__(**kwargs)
-        self.title = kwargs.get('title', _('RSS Feed'))
-        self.template = kwargs.get('template', 'admin_tools/dashboard/modules/feed.html')
-        self.feed_url = kwargs.get('feed_url')
-        self.limit = kwargs.get('limit')
+
+    title = _('RSS Feed')
+    template = 'admin_tools/dashboard/modules/feed.html'
+    feed_url = None
+    limit = None
 
     def init_with_context(self, context):
         import datetime
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.