Commits

Mikhail Korobov committed 67b8d0e

New API for menu items and dashboard modules. DashboardModule and MenuItem suffixes are removed from class names. Python namespaces should be used instead. Old names are deprecated but still work.

Comments (0)

Files changed (12)

admin_tools/dashboard/dashboards.py

 from django.template.defaultfilters import slugify
 from django.utils.importlib import import_module
 from django.utils.translation import ugettext_lazy as _
-from admin_tools.dashboard.modules import *
+from django.core.urlresolvers import reverse
+from django.contrib.contenttypes.models import ContentType
+from admin_tools.dashboard import modules
 
 class Dashboard(object):
     """
                 self.columns = 3
 
                 # append an app list module for "Applications"
-                self.children.append(modules.AppListDashboardModule(
+                self.children.append(modules.AppList(
                     title=_('Applications'),
                     exclude_list=('django.contrib',),
                 ))
 
                 # append an app list module for "Administration"
-                self.children.append(modules.AppListDashboardModule(
+                self.children.append(modules.AppList(
                     title=_('Administration'),
                     include_list=('django.contrib',),
                 ))
 
                 # append a recent actions module
-                self.children.append(modules.RecentActionsDashboardModule(
+                self.children.append(modules.RecentActions(
                     title=_('Recent Actions'),
                     limit=5
                 ))
 
                 # append a model list module that lists all models
                 # for the app
-                self.children.append(modules.ModelListDashboardModule(
+                self.children.append(modules.ModelList(
                     title=self.app_title,
                     include_list=self.models,
                 ))
 
                 # append a recent actions module for the current app
-                self.children.append(modules.RecentActionsDashboardModule(
+                self.children.append(modules.RecentActions(
                     title=_('Recent Actions'),
                     include_list=self.models,
                     limit=5
         Dashboard.__init__(self, **kwargs)
 
         # append a link list module for "quick links"
-        self.children.append(LinkListDashboardModule(
+        self.children.append(modules.LinkList(
             title=_('Quick links'),
             layout='inline',
             draggable=False,
         ))
 
         # append an app list module for "Applications"
-        self.children.append(AppListDashboardModule(
+        self.children.append(modules.AppList(
             title=_('Applications'),
             exclude_list=('django.contrib',),
         ))
 
         # append an app list module for "Administration"
-        self.children.append(AppListDashboardModule(
+        self.children.append(modules.AppList(
             title=_('Administration'),
             include_list=('django.contrib',),
         ))
 
         # append a recent actions module
-        self.children.append(RecentActionsDashboardModule(
+        self.children.append(modules.RecentActions(
             title=_('Recent Actions'),
             limit=5
         ))
 
         # append a feed module
-        self.children.append(FeedDashboardModule(
+        self.children.append(modules.Feed(
             title=_('Latest Django News'),
             feed_url='http://www.djangoproject.com/rss/weblog/',
             limit=5
         ))
 
         # append another link list module for "support".
-        self.children.append(LinkListDashboardModule(
+        self.children.append(modules.LinkList(
             title=_('Support'),
             children=[
                 {
         self.title = ''
 
         # append a model list module
-        self.children.append(ModelListDashboardModule(
+        self.children.append(modules.ModelList(
             title=self.app_title,
             include_list=self.models,
         ))
 
         # append a recent actions module
-        self.children.append(RecentActionsDashboardModule(
+        self.children.append(modules.RecentActions(
             title=_('Recent Actions'),
             include_list=self.get_app_content_types(),
             limit=5

admin_tools/dashboard/models.py

 class AppListDashboardModule(
           import_path_is_changed(
               'admin_tools.dashboard.models.AppListDashboardModule',
-              'admin_tools.dashboard.modules.AppListDashboardModule',
+              'admin_tools.dashboard.modules.AppList',
           ),
-          modules.AppListDashboardModule
+          modules.AppList
       ): pass
 
 class ModelListDashboardModule(
           import_path_is_changed(
               'admin_tools.dashboard.models.ModelListDashboardModule',
-              'admin_tools.dashboard.modules.ModelListDashboardModule',
+              'admin_tools.dashboard.modules.ModelList',
           ),
-          modules.ModelListDashboardModule
+          modules.ModelList
       ): pass
 
 class LinkListDashboardModule(
           import_path_is_changed(
               'admin_tools.dashboard.models.LinkListDashboardModule',
-              'admin_tools.dashboard.modules.LinkListDashboardModule',
+              'admin_tools.dashboard.modules.LinkList',
           ),
-          modules.LinkListDashboardModule
+          modules.LinkList
       ): pass
 
 class FeedDashboardModule(
           import_path_is_changed(
               'admin_tools.dashboard.models.FeedDashboardModule',
-              'admin_tools.dashboard.modules.FeedDashboardModule',
+              'admin_tools.dashboard.modules.Feed',
           ),
-          modules.FeedDashboardModule
+          modules.Feed
       ): pass

admin_tools/dashboard/modules.py

         example, let's build a "history" dashboard module, that will list the
         last ten visited pages::
 
-            class HistoryDashboardModule(LinkListDashboardModule):
+            from admin_tools.dashboard import modules
+
+            class HistoryDashboardModule(modules.LinkList):
                 def init_with_context(self, context):
                     self.title = 'History'
                     request = context['request']
         ret += self.css_classes
         return ' '.join(ret)
 
-class LinkListDashboardModule(DashboardModule):
+class LinkList(DashboardModule):
     """
     A module that displays a list of links.
     As well as the ``DashboardModule`` properties, the
-    ``LinkListDashboardModule`` takes an extra keyword argument:
+    ``LinkList`` takes an extra keyword argument:
 
     ``layout``
         The layout of the list, possible values are ``stacked`` and ``inline``.
             def __init__(self, **kwargs):
                 Dashboard.__init__(self, **kwargs)
 
-                self.children.append(modules.LinkListDashboardModule(
+                self.children.append(modules.LinkList(
                     layout='inline',
                     children=(
                         {
     """
 
     def __init__(self, **kwargs):
-        super(LinkListDashboardModule, self).__init__(**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')
 
 
-class AppListDashboardModule(DashboardModule, AppListElementMixin):
+class AppList(DashboardModule, AppListElementMixin):
     """
     Module that lists installed apps and their models.
     As well as the ``DashboardModule`` properties, the
-    ``AppListDashboardModule`` has two extra properties:
+    ``AppList`` has two extra properties:
 
     ``exclude_list``
         A list of apps to exclude, if an app name (e.g. "django.contrib.auth"
                 Dashboard.__init__(self, **kwargs)
 
                 # will only list the django.contrib apps
-                self.children.append(modules.AppListDashboardModule(
+                self.children.append(modules.AppList(
                     title='Administration',
                     include_list=('django.contrib',)
                 ))
                 # will list all apps except the django.contrib ones
-                self.children.append(modules.AppListDashboardModule(
+                self.children.append(modules.AppList(
                     title='Applications',
                     exclude_list=('django.contrib',)
                 ))
     """
 
     def __init__(self, **kwargs):
-        super(AppListDashboardModule, self).__init__(**kwargs)
+        super(AppList, self).__init__(**kwargs)
         self.title = kwargs.get('title', _('Applications'))
         self.template = kwargs.get('template',
                                    'admin_tools/dashboard/modules/app_list.html')
             self.children.append(apps[app])
 
 
-class ModelListDashboardModule(DashboardModule, AppListElementMixin):
+class ModelList(DashboardModule, AppListElementMixin):
     """
     Module that lists a set of models.
     As well as the ``DashboardModule`` properties, the
-    ``ModelListDashboardModule`` takes two extra keyword arguments:
+    ``ModelList`` takes two extra keyword arguments:
 
     ``include_list``
         A list of models to include, only models whose name (e.g.
                 Dashboard.__init__(self, **kwargs)
 
                 # will only list the django.contrib.auth models
-                self.children.append(modules.ModelListDashboardModule(
+                self.children.append(modules.ModelList(
                     title='Authentication',
                     include_list=('django.contrib.auth',)
                 ))
     """
 
     def __init__(self, **kwargs):
-        super(ModelListDashboardModule, self).__init__(**kwargs)
+        super(ModelList, self).__init__(**kwargs)
         self.title = kwargs.get('title', '')
         self.template = kwargs.get('template',
                                    'admin_tools/dashboard/modules/model_list.html')
         self.children.sort(lambda x, y: cmp(x['title'], y['title']))
 
 
-class RecentActionsDashboardModule(DashboardModule):
+class RecentActions(DashboardModule):
     """
     Module that lists the recent actions for the current user.
     As well as the ``DashboardModule`` properties, the
-    ``RecentActionsDashboardModule`` takes three extra keyword arguments:
+    ``RecentActions`` takes three extra keyword arguments:
 
     ``include_list``
         A list of contenttypes (e.g. "auth.group" or "sites.site") to include,
                 Dashboard.__init__(self, **kwargs)
 
                 # will only list the django.contrib apps
-                self.children.append(modules.RecentActionsDashboardModule(
+                self.children.append(modules.RecentActions(
                     title='Django CMS recent actions',
                     include_list=('cms.page', 'cms.cmsplugin',)
                 ))
     """
 
     def __init__(self, **kwargs):
-        super(RecentActionsDashboardModule, self).__init__(**kwargs)
+        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.pre_content = _('No recent actions.')
 
 
-class FeedDashboardModule(DashboardModule):
+class Feed(DashboardModule):
     """
     Class that represents a feed dashboard module.
 
         This class uses the
         `Universal Feed Parser module <http://www.feedparser.org/>`_ to parse
         the feeds, so you'll need to install it, all feeds supported by
-        FeedParser are thus supported by the FeedDashboardModule.
+        FeedParser are thus supported by the Feed
 
-    As well as the ``DashboardModule`` properties, the ``FeedDashboardModule``
+    As well as the ``DashboardModule`` properties, the ``Feed``
     takes two extra keyword arguments:
 
     ``feed_url``
                 Dashboard.__init__(self, **kwargs)
 
                 # will only list the django.contrib apps
-                self.children.append(modules.FeedDashboardModule(
+                self.children.append(modules.Feed(
                     title=_('Latest Django News'),
                     feed_url='http://www.djangoproject.com/rss/weblog/',
                     limit=5
     .. image:: images/feed_dashboard_module.png
     """
     def __init__(self, **kwargs):
-        super(FeedDashboardModule, self).__init__(**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')

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

         Dashboard.__init__(self, **kwargs)
 
         # append a link list module for "quick links"
-        self.children.append(modules.LinkListDashboardModule(
+        self.children.append(modules.LinkList(
             title=_('Quick links'),
             layout='inline',
             draggable=False,
         ))
 
         # append an app list module for "Applications"
-        self.children.append(modules.AppListDashboardModule(
+        self.children.append(modules.AppList(
             title=_('Applications'),
             exclude_list=('django.contrib',),
         ))
 
         # append an app list module for "Administration"
-        self.children.append(modules.AppListDashboardModule(
+        self.children.append(modules.AppList(
             title=_('Administration'),
             include_list=('django.contrib',),
         ))
 
         # append a recent actions module
-        self.children.append(modules.RecentActionsDashboardModule(
+        self.children.append(modules.RecentActions(
             title=_('Recent Actions'),
             limit=5
         ))
 
         # append a feed module
-        self.children.append(modules.FeedDashboardModule(
+        self.children.append(modules.Feed(
             title=_('Latest Django News'),
             feed_url='http://www.djangoproject.com/rss/weblog/',
             limit=5
         ))
 
         # append another link list module for "support".
-        self.children.append(modules.LinkListDashboardModule(
+        self.children.append(modules.LinkList(
             title=_('Support'),
             children=[
                 {
         self.title = ''
 
         # append a model list module
-        self.children.append(modules.ModelListDashboardModule(
+        self.children.append(modules.ModelList(
             title=self.app_title,
             include_list=self.models,
         ))
 
         # append a recent actions module
-        self.children.append(modules.RecentActionsDashboardModule(
+        self.children.append(modules.RecentActions(
             title=_('Recent Actions'),
             include_list=self.get_app_content_types(),
         ))

admin_tools/menu/items.py

             len([c for c in self.children if c.is_selected(request)]) > 0
 
 
-class AppListMenuItem(MenuItem, AppListElementMixin):
+class AppList(MenuItem, AppListElementMixin):
     """
     A menu item that lists installed apps an their models.
-    In addition to the parent ``MenuItem`` properties, the ``AppListMenuItem``
+    In addition to the parent ``MenuItem`` properties, the ``AppList``
     has two extra properties:
 
     ``exclude_list``
         class MyMenu(Menu):
             def __init__(self, **kwargs):
                 super(MyMenu, self).__init__(**kwargs)
-                self.children.append(items.AppListMenuItem(
+                self.children.append(items.AppList(
                     title='Applications',
                     exclude_list=('django.contrib',)
                 )
         """
         ``AppListMenuItem`` constructor.
         """
-        super(AppListMenuItem, self).__init__(**kwargs)
+        super(AppList, self).__init__(**kwargs)
         self.include_list = kwargs.get('include_list', [])
         self.exclude_list = kwargs.get('exclude_list', [])
 
             self.children.append(item)
 
 
-class BookmarkMenuItem(MenuItem, AppListElementMixin):
+class Bookmarks(MenuItem, AppListElementMixin):
     """
     A menu item that lists pages bookmarked by the user. This menu item also
     adds an extra button to the menu that allows the user to bookmark or
         class MyMenu(Menu):
             def __init__(self, **kwargs):
                 super(MyMenu, self).__init__(**kwargs)
-                self.children.append(items.BookmarkMenuItem(title='My bookmarks'))
+                self.children.append(items.Bookmarks(title='My bookmarks'))
 
     """
 
     def __init__(self, **kwargs):
-        super(BookmarkMenuItem, self).__init__(**kwargs)
+        super(Bookmarks, self).__init__(**kwargs)
         self.title = kwargs.get('title', _('Bookmarks'))
         if 'bookmark' not in self.css_classes:
             self.css_classes.append('bookmark')

admin_tools/menu/menus.py

 from django.core.urlresolvers import reverse
-from django.utils.safestring import mark_safe
-from django.utils.text import capfirst
 from django.utils.translation import ugettext_lazy as _
-from admin_tools.utils import AppListElementMixin
-from admin_tools.menu.items import MenuItem, BookmarkMenuItem, AppListMenuItem
+from admin_tools.menu import items
 
 class Menu(object):
     """
                     items.MenuItem(title='Home', url=reverse('admin:index'))
                 )
                 self.children.append(
-                    items.AppListMenuItem(title='Applications')
+                    items.AppList(title='Applications')
                 )
                 self.children.append(
                     items.MenuItem(
     """
     def __init__(self, **kwargs):
         super(DefaultMenu, self).__init__(**kwargs)
-        self.children.append(MenuItem(
+        self.children.append(items.MenuItem(
             title=_('Dashboard'),
             url=reverse('admin:index')
         ))
-        self.children.append(BookmarkMenuItem())
-        self.children.append(AppListMenuItem(
+        self.children.append(items.Bookmarks())
+        self.children.append(items.AppList(
             title=_('Applications'),
             exclude_list=('django.contrib',)
         ))
-        self.children.append(AppListMenuItem(
+        self.children.append(items.AppList(
             title=_('Administration'),
             include_list=('django.contrib',)
         ))

admin_tools/menu/models.py

 
 class Menu(
           import_path_is_changed(
-              'admin_tools.menu.models',
+              'admin_tools.menu.models.Menu',
               'admin_tools.menu.Menu'
           ),
           menu.Menu
 
 class AppListMenuItem(
           import_path_is_changed(
-              'admin_tools.menu.models.BookmarkMenuItem',
-              'admin_tools.menu.items.AppListMenuItem'
+              'admin_tools.menu.models.AppListMenuItem',
+              'admin_tools.menu.items.AppList'
           ),
-          items.AppListMenuItem
+          items.AppList
       ): pass
 
 class BookmarkMenuItem(
           import_path_is_changed(
               'admin_tools.menu.models.BookmarkMenuItem',
-              'admin_tools.menu.items.BookmarkMenuItem'
+              'admin_tools.menu.items.Bookmarks'
           ),
-          items.BookmarkMenuItem
+          items.Bookmarks
       ): pass

admin_tools/menu/templates/admin_tools/menu/menu.txt

             title=_('Dashboard'),
             url=reverse('admin:index')
         ))
-        self.children.append(items.AppListMenuItem(
+        self.children.append(items.AppList(
             title=_('Applications'),
             exclude_list=('django.contrib',)
         ))
-        self.children.append(items.AppListMenuItem(
+        self.children.append(items.AppList(
             title=_('Administration'),
             include_list=('django.contrib',)
         ))

admin_tools/tests.py

 
         from admin_tools.dashboard import modules
         self.assertNotDeprecated(modules.DashboardModule)
-        self.assertNotDeprecated(modules.AppListDashboardModule)
-        self.assertNotDeprecated(modules.ModelListDashboardModule)
-        self.assertNotDeprecated(modules.LinkListDashboardModule)
-        self.assertNotDeprecated(modules.FeedDashboardModule)
+        self.assertNotDeprecated(modules.AppList)
+        self.assertNotDeprecated(modules.ModelList)
+        self.assertNotDeprecated(modules.LinkList)
+        self.assertNotDeprecated(modules.Feed)
 
 
     def test_menu(self):
 
         from admin_tools.menu import items
         self.assertNotDeprecated(items.MenuItem)
-        self.assertNotDeprecated(items.AppListMenuItem)
-        self.assertNotDeprecated(items.BookmarkMenuItem)
+        self.assertNotDeprecated(items.AppList)
+        self.assertNotDeprecated(items.Bookmarks)

docs/dashboard.rst

 .. autoclass:: admin_tools.dashboard.modules.DashboardModule
     :members:
 
-The ``LinkListDashboardModule`` class
+The ``LinkList`` class
 -------------------------------------
 
-.. autoclass:: admin_tools.dashboard.modules.LinkListDashboardModule
+.. autoclass:: admin_tools.dashboard.modules.LinkList
     :members:
 
-The ``AppListDashboardModule`` class
+The ``AppList`` class
 ------------------------------------
 
-.. autoclass:: admin_tools.dashboard.modules.AppListDashboardModule
+.. autoclass:: admin_tools.dashboard.modules.AppList
     :members:
 
-The ``ModelListDashboardModule`` class
+The ``ModelList`` class
 --------------------------------------
 
-.. autoclass:: admin_tools.dashboard.modules.ModelListDashboardModule
+.. autoclass:: admin_tools.dashboard.modules.ModelList
     :members:
 
-The ``RecentActionsDashboardModule`` class
+The ``RecentActions`` class
 ------------------------------------------
 
-.. autoclass:: admin_tools.dashboard.modules.RecentActionsDashboardModule
+.. autoclass:: admin_tools.dashboard.modules.RecentActions
     :members:
 
-The ``FeedDashboardModule`` class
+The ``Feed`` class
 ---------------------------------
 
-.. autoclass:: admin_tools.dashboard.modules.FeedDashboardModule
+.. autoclass:: admin_tools.dashboard.modules.Feed
     :members:
 .. autoclass:: admin_tools.menu.items.MenuItem
     :members:
 
-The ``AppListMenuItem`` class
+The ``AppList`` class
 -----------------------------
 
-.. autoclass:: admin_tools.menu.items.AppListMenuItem
+.. autoclass:: admin_tools.menu.items.AppList
     :members:
 
-The ``BookmarkMenuItem`` class
+The ``Bookmarks`` class
 ------------------------------
 
-.. autoclass:: admin_tools.menu.items.BookmarkMenuItem
+.. autoclass:: admin_tools.menu.items.Bookmarks
     :members:

test_proj/dashboard.py

         Dashboard.__init__(self, **kwargs)
 
         # append a link list module for "quick links"
-        self.children.append(modules.LinkListDashboardModule(
+        self.children.append(modules.LinkList(
             title=_('Quick links'),
             layout='inline',
             draggable=False,
         ))
 
         # append an app list module for "Applications"
-        self.children.append(modules.AppListDashboardModule(
+        self.children.append(modules.AppList(
             title=_('Applications'),
             exclude_list=('django.contrib',),
         ))
 
         # append an app list module for "Administration"
-        self.children.append(modules.AppListDashboardModule(
+        self.children.append(modules.AppList(
             title=_('Administration'),
             include_list=('django.contrib',),
         ))
 
         # append a recent actions module
-        self.children.append(modules.RecentActionsDashboardModule(
+        self.children.append(modules.RecentActions(
             title=_('Recent Actions'),
             limit=5
         ))
 
         # append another link list module for "support".
-        self.children.append(modules.LinkListDashboardModule(
+        self.children.append(modules.LinkList(
             title=_('Support'),
             children=[
                 {
         self.title = ''
 
         # append a model list module
-        self.children.append(modules.ModelListDashboardModule(
+        self.children.append(modules.ModelList(
             title=self.app_title,
             include_list=self.models,
         ))
 
         # append a recent actions module
-        self.children.append(modules.RecentActionsDashboardModule(
+        self.children.append(modules.RecentActions(
             title=_('Recent Actions'),
             include_list=self.get_app_content_types(),
         ))