Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added ADMIN_MEDIA_PREFIX setting instead of hard-coding /m/

git-svn-id: http://code.djangoproject.com/svn/django/trunk@108 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 68baafc1100ceae5c8073975f8561e101a4ec1a4 1 parent 470db12
Adrian Holovaty authored July 16, 2005
2  django/conf/admin_templates/base.html
@@ -3,7 +3,7 @@
3 3
 <head>
4 4
 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5 5
 <title>{% block title %}{% endblock %}</title>
6  
-<link rel="stylesheet" type="text/css" href="{% block stylesheet %}/m/css/base.css{% endblock %}" />
  6
+<link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/base.css{% endblock %}" />
7 7
 {% block extrastyle %}{% endblock %}
8 8
 {% block extrahead %}{% endblock %}
9 9
 </head>
5  django/conf/global_settings.py
@@ -54,6 +54,11 @@
54 54
 # List of locations of the template source files, in search order.
55 55
 TEMPLATE_DIRS = ()
56 56
 
  57
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
  58
+# trailing slash.
  59
+# Examples: "http://foo.com/media/", "/media/".
  60
+ADMIN_MEDIA_PREFIX = '/media/'
  61
+
57 62
 # Default e-mail address to use for various automated correspondence from
58 63
 # the site managers.
59 64
 DEFAULT_FROM_EMAIL = 'webmaster@localhost'
5  django/conf/project_template/settings/admin.py
@@ -10,3 +10,8 @@
10 10
     'django.middleware.admin.AdminUserRequired',
11 11
     'django.middleware.common.CommonMiddleware',
12 12
 )
  13
+
  14
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
  15
+# trailing slash.
  16
+# Examples: "http://foo.com/media/", "/media/".
  17
+ADMIN_MEDIA_PREFIX = '/media/'
18  django/templatetags/adminmedia.py
... ...
@@ -0,0 +1,18 @@
  1
+from django.core import template
  2
+
  3
+class AdminMediaPrefixNode(template.Node):
  4
+    def render(self, context):
  5
+        try:
  6
+            from django.conf.settings import ADMIN_MEDIA_PREFIX
  7
+        except ImportError:
  8
+            return ''
  9
+        return ADMIN_MEDIA_PREFIX
  10
+
  11
+def admin_media_prefix(parser, token):
  12
+    """
  13
+    {% admin_media_prefix %}
  14
+    """
  15
+    bits = token.contents.split()
  16
+    return AdminMediaPrefixNode()
  17
+
  18
+template.register_tag('admin_media_prefix', admin_media_prefix)
21  django/views/admin/main.py
@@ -7,6 +7,7 @@
7 7
 from django.utils.html import strip_tags
8 8
 from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
9 9
 from django.utils.text import get_text_list
  10
+from django.conf.settings import ADMIN_MEDIA_PREFIX
10 11
 import operator
11 12
 
12 13
 # Text to display within changelist table cells if the value is blank.
@@ -276,7 +277,7 @@ def change_list(request, app_label, module_name):
276 277
     # Search form.
277 278
     if lookup_opts.admin.search_fields:
278 279
         raw_template.append('<div id="toolbar">\n<form id="changelist-search" action="" method="get">\n')
279  
-        raw_template.append('<label><img src="/m/img/admin/icon_searchbox.png" /></label> ')
  280
+        raw_template.append('<label><img src="%simg/admin/icon_searchbox.png" /></label> ' % ADMIN_MEDIA_PREFIX)
280 281
         raw_template.append('<input type="text" size="40" name="%s" value="%s" id="searchbar" /> ' % \
281 282
             (SEARCH_VAR, escape(query)))
282 283
         raw_template.append('<input type="submit" value="Go" /> ')
@@ -407,7 +408,7 @@ def change_list(request, app_label, module_name):
407 408
                     # Booleans are special: We use images.
408 409
                     elif isinstance(f, meta.BooleanField) or isinstance(f, meta.NullBooleanField):
409 410
                         BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'}
410  
-                        result_repr = '<img src="/m/img/admin/icon-%s.gif" alt="%s" />' % (BOOLEAN_MAPPING[field_val], field_val)
  411
+                        result_repr = '<img src="%simg/admin/icon-%s.gif" alt="%s" />' % (ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val)
411 412
                     # ImageFields are special: Use a thumbnail.
412 413
                     elif isinstance(f, meta.ImageField):
413 414
                         from django.parts.media.photos import get_thumbnail_url
@@ -536,15 +537,15 @@ def _get_template(opts, app_label, add=False, change=False, show_delete=False, f
536 537
     t.append('{% block extrahead %}')
537 538
 
538 539
     # Put in any necessary JavaScript imports.
539  
-    javascript_imports = ['/m/js/core.js', '/m/js/admin/RelatedObjectLookups.js']
  540
+    javascript_imports = ['%sjs/core.js' % ADMIN_MEDIA_PREFIX, '%sjs/admin/RelatedObjectLookups.js' % ADMIN_MEDIA_PREFIX]
540 541
     if 'collapse' in ' '.join([f[1].get('classes', '') for f in opts.admin.fields]):
541  
-        javascript_imports.append('/m/js/admin/CollapsedFieldsets.js')
  542
+        javascript_imports.append('%sjs/admin/CollapsedFieldsets.js' % ADMIN_MEDIA_PREFIX)
542 543
     if auto_populated_fields:
543  
-        javascript_imports.append('/m/js/urlify.js')
  544
+        javascript_imports.append('%sjs/urlify.js' % ADMIN_MEDIA_PREFIX)
544 545
     if opts.has_field_type(meta.DateTimeField) or opts.has_field_type(meta.TimeField) or opts.has_field_type(meta.DateField):
545  
-        javascript_imports.extend(['/m/js/calendar.js', '/m/js/admin/DateTimeShortcuts.js'])
  546
+        javascript_imports.extend(['%sjs/calendar.js' % ADMIN_MEDIA_PREFIX, '%sjs/admin/DateTimeShortcuts.js' % ADMIN_MEDIA_PREFIX])
546 547
     if ordered_objects:
547  
-        javascript_imports.extend(['/m/js/getElementsBySelector.js', '/m/js/dom-drag.js', '/m/js/admin/ordering.js'])
  548
+        javascript_imports.extend(['%sjs/getElementsBySelector.js' % ADMIN_MEDIA_PREFIX, '%sjs/dom-drag.js' % ADMIN_MEDIA_PREFIX, '%sjs/admin/ordering.js' % ADMIN_MEDIA_PREFIX])
548 549
     if opts.admin.js:
549 550
         javascript_imports.extend(opts.admin.js)
550 551
     for _, options in opts.admin.fields:
@@ -552,7 +553,7 @@ def _get_template(opts, app_label, add=False, change=False, show_delete=False, f
552 553
             for field_list in options['fields']:
553 554
                 for f in field_list:
554 555
                     if f.rel and isinstance(f, meta.ManyToManyField) and f.rel.filter_interface:
555  
-                        javascript_imports.extend(['/m/js/SelectBox.js', '/m/js/SelectFilter2.js'])
  556
+                        javascript_imports.extend(['%sjs/SelectBox.js' % ADMIN_MEDIA_PREFIX, '%sjs/SelectFilter2.js' % ADMIN_MEDIA_PREFIX])
556 557
                         raise StopIteration
557 558
         except StopIteration:
558 559
             break
@@ -737,7 +738,7 @@ def _get_admin_field_form_widget(field, name_prefix, rel, add, change):
737 738
     if use_raw_id_admin(field):
738 739
         t.append(' <a href="../../../%s/%s/" class="related-lookup" id="lookup_%s" onclick="return showRelatedObjectLookupPopup(this);">' % \
739 740
                     (field.rel.to.app_label, field.rel.to.module_name, field_id))
740  
-        t.append('<img src="/m/img/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>')
  741
+        t.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % ADMIN_MEDIA_PREFIX)
741 742
     # fields with relationships to editable objects get an "add another" link,
742 743
     # but only if the field doesn't have raw_admin ('cause in that case they get
743 744
     # the "add" button in the popup)
@@ -745,7 +746,7 @@ def _get_admin_field_form_widget(field, name_prefix, rel, add, change):
745 746
         t.append('{%% if perms.%s.%s %%}' % (field.rel.to.app_label, field.rel.to.get_add_permission()))
746 747
         t.append(' <a href="../../../%s/%s/add/" class="add-another" id="add_%s" onclick="return showAddAnotherPopup(this);">' % \
747 748
                     (field.rel.to.app_label, field.rel.to.module_name, field_id))
748  
-        t.append('<img src="/m/img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another" /></a>')
  749
+        t.append('<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="Add Another" /></a>' % ADMIN_MEDIA_PREFIX)
749 750
         t.append('{% endif %}')
750 751
     return ''.join(t)
751 752
 

0 notes on commit 68baafc

Please sign in to comment.
Something went wrong with that request. Please try again.