Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2869 -- Do not append ADMIN_MEDIA_PREFIX to absolute-path URLs…

… used for

included javascript. Based on patches from SmileyChris and oyvind@saltvik.no.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@4692 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ab64b383177f8e554c876d7c8574df6169ecc515 1 parent cc8d656
Malcolm Tredinnick authored March 09, 2007
10  django/contrib/admin/templatetags/admin_modify.py
@@ -11,6 +11,7 @@
11 11
 register = template.Library()
12 12
 
13 13
 word_re = re.compile('[A-Z][a-z]+')
  14
+absolute_url_re = re.compile(r'^(?:http(?:s)?:/)?/', re.IGNORECASE)
14 15
 
15 16
 def class_name_to_underscored(name):
16 17
     return '_'.join([s.lower() for s in word_re.findall(name)[:-1]])
@@ -18,18 +19,19 @@ def class_name_to_underscored(name):
18 19
 def include_admin_script(script_path):
19 20
     """
20 21
     Returns an HTML script element for including a script from the admin
21  
-    media url.
  22
+    media url (or other location if an absolute url is given).
22 23
 
23 24
     Example usage::
24 25
 
25  
-        {% include_admin_script js/calendar.js %}
  26
+        {% include_admin_script "js/calendar.js" %}
26 27
 
27 28
     could return::
28 29
 
29 30
         <script type="text/javascript" src="/media/admin/js/calendar.js">
30 31
     """
31  
-
32  
-    return '<script type="text/javascript" src="%s%s"></script>' % (settings.ADMIN_MEDIA_PREFIX, script_path)
  32
+    if not absolute_url_re.match(script_path):
  33
+        script_path = '%s%s' % (settings.ADMIN_MEDIA_PREFIX, script_path)
  34
+    return '<script type="text/javascript" src="%s"></script>' % script_path
33 35
 include_admin_script = register.simple_tag(include_admin_script)
34 36
 
35 37
 def submit_row(context):
3  docs/model-api.txt
@@ -1216,6 +1216,9 @@ screen via ``<script src="">`` tags. This can be used to tweak a given type of
1216 1216
 admin page in JavaScript or to provide "quick links" to fill in default values
1217 1217
 for certain fields.
1218 1218
 
  1219
+If relative URLs are used, Django admin will automatically prepend these links
  1220
+with ``settings.ADMIN_MEDIA_PREFIX``.
  1221
+
1219 1222
 ``list_display``
1220 1223
 ----------------
1221 1224
 

0 notes on commit ab64b38

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