Commits

David Jean Louis  committed 14a545c

add support for django-staticfiles (fixes issue #21), thanks @dstufft.

  • Participants
  • Parent commits 50a618a

Comments (0)

Files changed (4)

File admin_tools/dashboard/templatetags/admin_tools_dashboard_tags.py

 import math
 from django import template
 from django.conf import settings
+from admin_tools.utils import get_media_url
 from admin_tools.dashboard.utils import get_dashboard
 
 register = template.Library()
     if dashboard is None:
         dashboard = get_dashboard(context, location)
 
-    try:
-        media_url = settings.STATIC_URL
-    except AttributeError:
-        media_url = settings.MEDIA_URL
-
     dashboard.init_with_context(context)
     context.update({
         'template': dashboard.template,
         'dashboard': dashboard,
         'split_at': math.ceil(float(len(dashboard.children))/float(dashboard.columns)),
-        'media_url': media_url.rstrip('/'),
+        'media_url': get_media_url(),
         'has_disabled_modules': len([m for m in dashboard.children \
                                 if not m.enabled]) > 0,
     })
     if dashboard is None:
         dashboard = get_dashboard(context, location)
 
-    try:
-        media_url = settings.STATIC_URL
-    except AttributeError:
-        media_url = settings.MEDIA_URL
-
     context.update({
         'template' : 'dashboard/css.html',
         'css_files': dashboard.Media.css,
-        'media_url': media_url.rstrip('/'),
+        'media_url': get_media_url(),
     })
     return context
 admin_tools_render_dashboard_css = tag_func(admin_tools_render_dashboard_css)

File admin_tools/menu/templatetags/admin_tools_menu_tags.py

 from django import template
 from django.conf import settings
 from django.http import HttpRequest
+from admin_tools.utils import get_media_url
 from admin_tools.menu.models import Bookmark, BookmarkMenuItem
 from admin_tools.menu.utils import get_admin_menu
 
     if menu is None:
         menu = get_admin_menu()
 
-    try:
-        media_url = settings.STATIC_URL
-    except AttributeError:
-        media_url = settings.MEDIA_URL
-
     menu.init_with_context(context)
     has_bookmark_item = False
     bookmark = None
     context.update({
         'template': menu.template,
         'menu': menu,
-        'media_url': media_url.rstrip('/'),
+        'media_url': get_media_url(),
         'has_bookmark_item': has_bookmark_item,
         'bookmark': bookmark,
     })
     if menu is None:
         menu = get_admin_menu()
 
-    try:
-        media_url = settings.STATIC_URL
-    except AttributeError:
-        media_url = settings.MEDIA_URL
-
     context.update({
         'template': 'menu/css.html',
         'css_files': menu.Media.css,
-        'media_url': media_url.rstrip('/'),
+        'media_url': get_media_url(),
     })
     return context
 admin_tools_render_menu_css = tag_func(admin_tools_render_menu_css)

File admin_tools/theming/templatetags/theming_tags.py

 import os.path
 from django import template
 from django.conf import settings
+from admin_tools.utils import get_media_url
 
 register = template.Library()
 
     Template tag that renders the needed css files for the theming app.
     """
     css = getattr(settings, 'ADMIN_TOOLS_THEMING_CSS', False)
-    try:
-        media_url = settings.STATIC_URL
-    except AttributeError:
-        media_url = settings.MEDIA_URL
     if css:
-        css = os.path.join(media_url, css)
+        css = os.path.join(get_media_url(), css)
     else:
-        css = os.path.join(
-            getattr(settings, 'ADMIN_TOOLS_MEDIA_URL', media_url),
-            'admin_tools',
-            'css',
-            'theming.css'
-        )
+        css = os.path.join(get_media_url(), 'admin_tools', 'css', 'theming.css')
     return '<link rel="stylesheet" type="text/css" media="screen" href="%s" />' % css
 register.simple_tag(render_theming_css)

File admin_tools/utils.py

     def _get_admin_add_url(self, model):
         app_label = model._meta.app_label
         return reverse('admin:%s_%s_add' % (app_label, model.__name__.lower()))
+
+
+def get_media_url():
+    """
+    Returns the django admin tools media URL.
+    """
+    return getattr(
+        settings,
+        'ADMIN_TOOLS_MEDIA_URL',
+        getattr(settings, 'STATIC_URL', settings.MEDIA_URL)
+    ).rstrip('/')