Commits

David Jean Louis  committed 70b7b40

Completed support for multiple admin sites

  • Participants
  • Parent commits 9d5b945

Comments (0)

Files changed (8)

File admin_tools/dashboard/dashboards.py

 from django.utils.translation import ugettext_lazy as _
 from django.core.urlresolvers import reverse
 from django.contrib.contenttypes.models import ContentType
+
 from admin_tools.dashboard import modules
+from admin_tools.utils import get_admin_site_name
 
 
 class Dashboard(object):
     And then set the ``ADMIN_TOOLS_INDEX_DASHBOARD`` settings variable to
     point to your custom index dashboard class.
     """
-    def __init__(self, **kwargs):
-        Dashboard.__init__(self, **kwargs)
-
+    def init_with_context(self, context):
+        site_name = get_admin_site_name(context)
         # append a link list module for "quick links"
         self.children.append(modules.LinkList(
             _('Quick links'),
             collapsible=False,
             children=[
                 [_('Return to site'), '/'],
-                [_('Change password'), reverse('admin:password_change')],
-                [_('Log out'), reverse('admin:logout')],
+                [_('Change password'),
+                 reverse('%s:password_change' % site_name)],
+                [_('Log out'), reverse('%s:logout' % site_name)],
             ]
         ))
 

File admin_tools/dashboard/modules.py

 """
 Module where admin tools dashboard modules classes are defined.
 """
+
 from django.utils.text import capfirst
 from django.core.urlresolvers import reverse
 from django.contrib.contenttypes.models import ContentType
 from django.utils.translation import ugettext_lazy as _
+from django.utils.itercompat import is_iterable
+
 from admin_tools.utils import AppListElementMixin
-from django.utils.itercompat import is_iterable
+
 
 class DashboardModule(object):
     """
             if app_label not in apps:
                 apps[app_label] = {
                     'title': capfirst(app_label.title()),
-                    'url': reverse('admin:app_list', args=(app_label,)),
+                    'url': self._get_admin_app_list_url(model, context),
                     'models': []
                 }
             model_dict = {}

File admin_tools/dashboard/templates/admin_tools/dashboard/modules/recent_actions.html

         {% if child.is_deletion %}
         <span class="deletelink">{% if child.content_type %}{% filter capfirst %}{% trans child.content_type.name %}{% endfilter %}&nbsp;{% endif %}{{ child.object_repr }}</span>
         {% else %}
-        <a href="{% url admin:index %}{{ child.get_admin_url }}" class="{% if child.is_addition %} addlink{% endif %}{% if child.is_change %} changelink{% endif %}">{% if child.content_type %}{% filter capfirst %}{% trans child.content_type.name %}{% endfilter %}&nbsp;{% endif %}{{ child.object_repr }}</a>
+        <a href="{{ admin_url }}{{ child.get_admin_url }}" class="{% if child.is_addition %} addlink{% endif %}{% if child.is_change %} changelink{% endif %}">{% if child.content_type %}{% filter capfirst %}{% trans child.content_type.name %}{% endfilter %}&nbsp;{% endif %}{{ child.object_repr }}</a>
         {% endif %}
     </li>
     {% endfor %}

File admin_tools/dashboard/templatetags/admin_tools_dashboard_tags.py

 """
 
 import math
+
 from django import template
-from admin_tools.utils import get_media_url
+from django.core.urlresolvers import reverse
+
+from admin_tools.utils import get_media_url, get_admin_site_name
 from admin_tools.dashboard.utils import get_dashboard
 from admin_tools.dashboard.models import DashboardPreferences
 
         'media_url': get_media_url(),
         'has_disabled_modules': len([m for m in dashboard.children \
                                 if not m.enabled]) > 0,
+        'admin_url': reverse('%s:index' % get_admin_site_name(context)),
     })
     return context
 admin_tools_render_dashboard = tag_func(admin_tools_render_dashboard)
         'module': module,
         'index': index,
         'subindex': subindex,
+        'admin_url': reverse('%s:index' % get_admin_site_name(context)),
     })
     return context
 admin_tools_render_dashboard_module = tag_func(admin_tools_render_dashboard_module)

File admin_tools/menu/items.py

             if app_label not in apps:
                 apps[app_label] = {
                     'title': capfirst(app_label.title()),
-                    'url': reverse('admin:app_list', args=(app_label,)),
+                    'url': self._get_admin_app_list_url(model, context),
                     'models': []
                 }
             apps[app_label]['models'].append({
         return len(self.children) == 0
 
 
-
 class ModelList(MenuItem, AppListElementMixin):
     """
     A menu item that lists a set of models.

File admin_tools/menu/menus.py

+"""
+Module where admin tools menu classes are defined.
+"""
+
 from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext_lazy as _
+
 from admin_tools.menu import items
+from admin_tools.utils import get_admin_site_name
+
 
 class Menu(object):
     """
     And then set the ``ADMIN_TOOLS_MENU`` settings variable to point to your
     custom menu class.
     """
-    def __init__(self, **kwargs):
-        super(DefaultMenu, self).__init__(**kwargs)
+    def init_with_context(self, context):
+        site_name = get_admin_site_name(context)
 
         self.children += [
-            items.MenuItem(_('Dashboard'), reverse('admin:index')),
+            items.MenuItem(_('Dashboard'), reverse('%s:index' % site_name)),
             items.Bookmarks(),
             items.AppList(
                 _('Applications'),

File admin_tools/menu/templatetags/admin_tools_menu_tags.py

 """
 
 from django import template
-from admin_tools.utils import get_media_url
+from django.core.urlresolvers import reverse
+
+from admin_tools.utils import get_media_url, get_admin_site_name
 from admin_tools.menu import items
 from admin_tools.menu.models import Bookmark
 from admin_tools.menu.utils import get_admin_menu
         'media_url': get_media_url(),
         'has_bookmark_item': has_bookmark_item,
         'bookmark': bookmark,
+        'admin_url': reverse('%s:index' % get_admin_site_name(context)),
     })
     return context
 admin_tools_render_menu = tag_func(admin_tools_render_menu)
         'template': item.template,
         'item': item,
         'index': index,
-        'selected': item.is_selected(context['request'])
+        'selected': item.is_selected(context['request']),
+        'admin_url': reverse('%s:index' % get_admin_site_name(context)),
     })
     return context
 admin_tools_render_menu_item = tag_func(admin_tools_render_menu_item)

File admin_tools/utils.py

             included = ["*"]
         return filter_models(request, included, excluded)
     
+    def _get_admin_app_list_url(self, model, context):
+        """
+        Returns the admin change url.
+        """
+        app_label = model._meta.app_label
+        return reverse('%s:app_list' % get_admin_site_name(context),
+                       args=(app_label,))
+    
     def _get_admin_change_url(self, model, context):
         """
         Returns the admin change url.
         """
         app_label = model._meta.app_label
         return reverse('%s:%s_%s_add' % (get_admin_site_name(context),
-                                            app_label,
-                                            model.__name__.lower()))
+                                         app_label,
+                                         model.__name__.lower()))
 
 def get_media_url():
     """