Ticket #2869: admin_js.patch

File admin_js.patch, 1.6 KB (added by SmileyChris, 9 years ago)
  • django/contrib/admin/templatetags/admin_modify.py

     
    1818def include_admin_script(script_path):
    1919    """
    2020    Returns an HTML script element for including a script from the admin
    21     media url.
     21    media url (or other location if an absolute url is given).
    2222
    2323    Example usage::
    2424
    25         {% include_admin_script js/calendar.js %}
     25        {% include_admin_script "js/calendar.js" %}
    2626
    2727    could return::
    2828
    2929        <script type="text/javascript" src="/media/admin/js/calendar.js">
    3030    """
    31 
    32     return '<script type="text/javascript" src="%s%s"></script>' % (settings.ADMIN_MEDIA_PREFIX, script_path)
     31    if not script_path.startswith('/') and '://' not in script_path:
     32        script_path = '%s%s' % (settings.ADMIN_MEDIA_PREFIX, script_path)
     33    return '<script type="text/javascript" src="%s"></script>' % script_path
    3334include_admin_script = register.simple_tag(include_admin_script)
    3435
    3536def submit_row(context):
  • docs/model-api.txt

     
    12061206admin page in JavaScript or to provide "quick links" to fill in default values
    12071207for certain fields.
    12081208
     1209If relative URLs are used, Django admin will automatically prepend these links
     1210with ``settings.ADMIN_MEDIA_PREFIX``.
     1211
    12091212``list_display``
    12101213----------------
    12111214
Back to Top