Commits

Mikhail Korobov committed ec36fe9

More positional args + less verbose LinkList link definitions

  • Participants
  • Parent commits d473b45

Comments (0)

Files changed (4)

admin_tools/dashboard/dashboards.py

             deletable=False,
             collapsible=False,
             children=[
-                {
-                    'title': _('Return to site'),
-                    'url': '/',
-                },
-                {
-                    'title': _('Change password'),
-                    'url': reverse('admin:password_change'),
-                },
-                {
-                    'title': _('Log out'),
-                    'url': reverse('admin:logout')
-                },
+                [_('Return to site'), '/'],
+                [_('Change password'), reverse('admin:password_change')],
+                [_('Log out'), reverse('admin:logout')],
             ]
         ))
 
         ))
 
         # append a recent actions module
-        self.children.append(modules.RecentActions(
-            _('Recent Actions'),
-            limit=5
-        ))
+        self.children.append(modules.RecentActions(_('Recent Actions'), 5))
 
         # append a feed module
         self.children.append(modules.Feed(

admin_tools/dashboard/modules.py

 from django.contrib.contenttypes.models import ContentType
 from django.utils.translation import ugettext_lazy as _
 from admin_tools.utils import AppListElementMixin
+from django.utils.itercompat import is_iterable
 
 class DashboardModule(object):
     """
         A string describing the link, it will be the ``title`` attribute of
         the html ``a`` tag.
 
+    Children can also be iterables (lists or tuples) of length 2, 3 or 4.
+
     Here's a small example of building a link list module::
 
         from admin_tools.dashboard import modules, Dashboard
                             'external': True,
                             'description': 'Python programming language rocks !',
                         },
-                        {
-                            'title': 'Django website',
-                            'url': 'http://www.djangoproject.com',
-                            'external': True
-                        },
-                        {
-                            'title': 'Some internal link',
-                            'url': '/some/internal/link/',
-                            'external': False
-                        },
+                        ['Django website', 'http://www.djangoproject.com', True],
+                        ['Some internal link', '/some/internal/link/'],
                     )
                 ))
 
     template = 'admin_tools/dashboard/modules/link_list.html'
     layout = 'stacked'
 
+    def init_with_context(self, context):
+        new_children = []
+        for link in self.children:
+            if isinstance(link, (tuple, list,)):
+                link_dict = {'title': link[0], 'url': link[1]}
+                if len(link) >= 3:
+                    link_dict['external'] = link[3]
+                if len(link) >= 4:
+                    link_dict['description'] = link[4]
+                new_children.append(link_dict)
+            else:
+                new_children.append(link)
+        self.children = new_children
+
 
 class AppList(DashboardModule, AppListElementMixin):
     """
     template = 'admin_tools/dashboard/modules/recent_actions.html'
     limit = 10
 
-    def __init__(self, title=None, **kwargs):
-        self.include_list = kwargs.pop('include_list', [])
-        self.exclude_list = kwargs.pop('exclude_list', [])
+    def __init__(self, title=None, limit=None,
+                 include_list=None, exclude_list=None, **kwargs):
+        self.include_list = include_list or []
+        self.exclude_list = exclude_list or []
+        self.limit = self.__class__.limit or limit
         super(RecentActions, self).__init__(title, **kwargs)
 
     def init_with_context(self, context):
     feed_url = None
     limit = None
 
+    def __init__(self, title=None, feed_url=None, limit=None, **kwargs):
+        kwargs.update({'feed_url': feed_url, 'limit': limit})
+        super(Feed, self).__init__(title, **kwargs)
+
     def init_with_context(self, context):
         import datetime
         if self.feed_url is None:

admin_tools/dashboard/templates/admin_tools/dashboard/dashboard.txt

             deletable=False,
             collapsible=False,
             children=[
-                {
-                    'title': _('Return to site'),
-                    'url': '/',
-                },
-                {
-                    'title': _('Change password'),
-                    'url': reverse('admin:password_change'),
-                },
-                {
-                    'title': _('Log out'),
-                    'url': reverse('admin:logout')
-                },
+                [_('Return to site'), '/'],
+                [_('Change password'), reverse('admin:password_change')],
+                [_('Log out'), reverse('admin:logout')],
             ]
         ))
 

test_proj/dashboard.py

             deletable=False,
             collapsible=False,
             children=[
-                {
-                    'title': _('Return to site'),
-                    'url': '/',
-                },
-                {
-                    'title': _('Change password'),
-                    'url': reverse('admin:password_change'),
-                },
-                {
-                    'title': _('Log out'),
-                    'url': reverse('admin:logout')
-                },
+                [_('Return to site'), '/'],
+                [_('Change password'), reverse('admin:password_change')],
+                [_('Log out'), reverse('admin:logout')],
             ]
         ))
 
 
         self.children.append(modules.ModelList(
             'Test1',
-            models = ['django.contrib.auth.*', '*.Site', '*.Foo'],
-            exclude = ['django.contrib.auth.models.User', 'test_app.*']
+            ['django.contrib.auth.*', '*.Site', '*.Foo'],
+            ['django.contrib.auth.models.User', 'test_app.*']
         ))
 
         # append a recent actions module
-        self.children.append(modules.RecentActions(
-            _('Recent Actions'),
-            limit=5
-        ))
+        self.children.append(
+             modules.RecentActions(_('Recent Actions'), 5)
+        )
 
         # append another link list module for "support".
         self.children.append(modules.LinkList(