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
This commit is contained in:
parent
cc8d656569
commit
ab64b38317
|
@ -11,6 +11,7 @@ import re
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
word_re = re.compile('[A-Z][a-z]+')
|
word_re = re.compile('[A-Z][a-z]+')
|
||||||
|
absolute_url_re = re.compile(r'^(?:http(?:s)?:/)?/', re.IGNORECASE)
|
||||||
|
|
||||||
def class_name_to_underscored(name):
|
def class_name_to_underscored(name):
|
||||||
return '_'.join([s.lower() for s in word_re.findall(name)[:-1]])
|
return '_'.join([s.lower() for s in word_re.findall(name)[:-1]])
|
||||||
|
@ -18,18 +19,19 @@ def class_name_to_underscored(name):
|
||||||
def include_admin_script(script_path):
|
def include_admin_script(script_path):
|
||||||
"""
|
"""
|
||||||
Returns an HTML script element for including a script from the admin
|
Returns an HTML script element for including a script from the admin
|
||||||
media url.
|
media url (or other location if an absolute url is given).
|
||||||
|
|
||||||
Example usage::
|
Example usage::
|
||||||
|
|
||||||
{% include_admin_script js/calendar.js %}
|
{% include_admin_script "js/calendar.js" %}
|
||||||
|
|
||||||
could return::
|
could return::
|
||||||
|
|
||||||
<script type="text/javascript" src="/media/admin/js/calendar.js">
|
<script type="text/javascript" src="/media/admin/js/calendar.js">
|
||||||
"""
|
"""
|
||||||
|
if not absolute_url_re.match(script_path):
|
||||||
return '<script type="text/javascript" src="%s%s"></script>' % (settings.ADMIN_MEDIA_PREFIX, script_path)
|
script_path = '%s%s' % (settings.ADMIN_MEDIA_PREFIX, script_path)
|
||||||
|
return '<script type="text/javascript" src="%s"></script>' % script_path
|
||||||
include_admin_script = register.simple_tag(include_admin_script)
|
include_admin_script = register.simple_tag(include_admin_script)
|
||||||
|
|
||||||
def submit_row(context):
|
def submit_row(context):
|
||||||
|
|
|
@ -1216,6 +1216,9 @@ screen via ``<script src="">`` tags. This can be used to tweak a given type of
|
||||||
admin page in JavaScript or to provide "quick links" to fill in default values
|
admin page in JavaScript or to provide "quick links" to fill in default values
|
||||||
for certain fields.
|
for certain fields.
|
||||||
|
|
||||||
|
If relative URLs are used, Django admin will automatically prepend these links
|
||||||
|
with ``settings.ADMIN_MEDIA_PREFIX``.
|
||||||
|
|
||||||
``list_display``
|
``list_display``
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue