Ticket #18035: 18035-1.diff

File 18035-1.diff, 22.4 KB (added by Claude Paroz, 13 years ago)

AdminMediaHandler removal

  • django/contrib/admin/static/admin/js/SelectFilter2.js

    diff --git a/django/contrib/admin/static/admin/js/SelectFilter2.js b/django/contrib/admin/static/admin/js/SelectFilter2.js
    index 0accd08..24d88f7 100644
    a b function findForm(node) {  
    1313}
    1414
    1515window.SelectFilter = {
    16     init: function(field_id, field_name, is_stacked, admin_media_prefix) {
     16    init: function(field_id, field_name, is_stacked, admin_static_prefix) {
    1717        if (field_id.match(/__prefix__/)){
    1818            // Don't intialize on empty forms.
    1919            return;
    window.SelectFilter = {  
    4343        var selector_available = quickElement('div', selector_div, '');
    4444        selector_available.className = 'selector-available';
    4545        var title_available = quickElement('h2', selector_available, interpolate(gettext('Available %s') + ' ', [field_name]));
    46         quickElement('img', title_available, '', 'src', admin_media_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of available %s. You may choose some by selecting them in the box below and then clicking the "Choose" arrow between the two boxes.'), [field_name]));
     46        quickElement('img', title_available, '', 'src', admin_static_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of available %s. You may choose some by selecting them in the box below and then clicking the "Choose" arrow between the two boxes.'), [field_name]));
    4747
    4848        var filter_p = quickElement('p', selector_available, '', 'id', field_id + '_filter');
    4949        filter_p.className = 'selector-filter';
    5050
    5151        var search_filter_label = quickElement('label', filter_p, '', 'for', field_id + "_input");
    5252
    53         var search_selector_img = quickElement('img', search_filter_label, '', 'src', admin_media_prefix + 'img/selector-search.gif', 'class', 'help-tooltip', 'alt', '', 'title', interpolate(gettext("Type into this box to filter down the list of available %s."), [field_name]));
     53        var search_selector_img = quickElement('img', search_filter_label, '', 'src', admin_static_prefix + 'img/selector-search.gif', 'class', 'help-tooltip', 'alt', '', 'title', interpolate(gettext("Type into this box to filter down the list of available %s."), [field_name]));
    5454
    5555        filter_p.appendChild(document.createTextNode(' '));
    5656
    window.SelectFilter = {  
    7373        var selector_chosen = quickElement('div', selector_div, '');
    7474        selector_chosen.className = 'selector-chosen';
    7575        var title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Chosen %s') + ' ', [field_name]));
    76         quickElement('img', title_chosen, '', 'src', admin_media_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of chosen %s. You may remove some by selecting them in the box below and then clicking the "Remove" arrow between the two boxes.'), [field_name]));
     76        quickElement('img', title_chosen, '', 'src', admin_static_prefix + 'img/icon-unknown.gif', 'width', '10', 'height', '10', 'class', 'help help-tooltip', 'title', interpolate(gettext('This is the list of chosen %s. You may remove some by selecting them in the box below and then clicking the "Remove" arrow between the two boxes.'), [field_name]));
    7777
    7878        var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', 'multiple', 'size', from_box.size, 'name', from_box.getAttribute('name'));
    7979        to_box.className = 'filtered';
  • django/contrib/gis/admin/widgets.py

    diff --git a/django/contrib/gis/admin/widgets.py b/django/contrib/gis/admin/widgets.py
    index 6dbbc60..aaffae8 100644
    a b from django.contrib.gis.geos import GEOSGeometry, GEOSException  
    88
    99# Creating a template context that contains Django settings
    1010# values needed by admin map templates.
    11 geo_context = Context({'ADMIN_MEDIA_PREFIX' : static('admin/'),
    12                        'LANGUAGE_BIDI' : translation.get_language_bidi()})
     11geo_context = Context({'LANGUAGE_BIDI' : translation.get_language_bidi()})
    1312
    1413class OpenLayersWidget(Textarea):
    1514    """
  • django/core/management/commands/runserver.py

    diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
    index e93af96..fa8a055 100644
    a b import sys  
    55import socket
    66
    77from django.core.management.base import BaseCommand, CommandError
    8 from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
     8from django.core.servers.basehttp import run, WSGIServerException, get_internal_wsgi_application
    99from django.utils import autoreload
    1010
    1111naiveip_re = re.compile(r"""^(?:
    class BaseRunserverCommand(BaseCommand):  
    127127            if shutdown_message:
    128128                self.stdout.write("%s\n" % shutdown_message)
    129129            sys.exit(0)
    130 
    131 class Command(BaseRunserverCommand):
    132     option_list = BaseRunserverCommand.option_list + (
    133         make_option('--adminmedia', dest='admin_media_path', default='',
    134             help='Specifies the directory from which to serve admin media.'),
    135     )
    136 
    137     def get_handler(self, *args, **options):
    138         """
    139         Serves admin media like old-school (deprecation pending).
    140         """
    141         handler = super(Command, self).get_handler(*args, **options)
    142         return AdminMediaHandler(handler, options.get('admin_media_path'))
  • django/core/servers/basehttp.py

    diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py
    index 8d4ceab..61222d2 100644
    a b from django.core.exceptions import ImproperlyConfigured  
    2222from django.core.management.color import color_style
    2323from django.core.wsgi import get_wsgi_application
    2424from django.utils.importlib import import_module
    25 from django.utils._os import safe_join
    26 from django.views import static
    2725
    2826from django.contrib.staticfiles import handlers
    2927
    class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):  
    131129
    132130    def __init__(self, *args, **kwargs):
    133131        from django.conf import settings
    134         self.admin_media_prefix = urlparse.urljoin(settings.STATIC_URL, 'admin/')
     132        self.admin_static_prefix = urlparse.urljoin(settings.STATIC_URL, 'admin/')
    135133        # We set self.path to avoid crashes in log_message() on unsupported
    136134        # requests (like "OPTIONS").
    137135        self.path = ''
    class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):  
    173171
    174172    def log_message(self, format, *args):
    175173        # Don't bother logging requests for admin images or the favicon.
    176         if (self.path.startswith(self.admin_media_prefix)
     174        if (self.path.startswith(self.admin_static_prefix)
    177175                or self.path == '/favicon.ico'):
    178176            return
    179177
    class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):  
    200198        sys.stderr.write(msg)
    201199
    202200
    203 class AdminMediaHandler(handlers.StaticFilesHandler):
    204     """
    205     WSGI middleware that intercepts calls to the admin media directory, as
    206     defined by the STATIC_URL setting, and serves those images.
    207     Use this ONLY LOCALLY, for development! This hasn't been tested for
    208     security and is not super efficient.
    209 
    210     This is pending for deprecation since 1.3.
    211     """
    212     def get_base_dir(self):
    213         return os.path.join(django.__path__[0], 'contrib', 'admin', 'static', 'admin')
    214 
    215     def get_base_url(self):
    216         from django.conf import settings
    217         return urlparse.urljoin(settings.STATIC_URL, 'admin/')
    218 
    219     def file_path(self, url):
    220         """
    221         Returns the path to the media file on disk for the given URL.
    222 
    223         The passed URL is assumed to begin with ``self.base_url``.  If the
    224         resulting file path is outside the media directory, then a ValueError
    225         is raised.
    226         """
    227         relative_url = url[len(self.base_url[2]):]
    228         relative_path = urllib.url2pathname(relative_url)
    229         return safe_join(self.base_dir, relative_path)
    230 
    231     def serve(self, request):
    232         document_root, path = os.path.split(self.file_path(request.path))
    233         return static.serve(request, path, document_root=document_root)
    234 
    235     def _should_handle(self, path):
    236         """
    237         Checks if the path should be handled. Ignores the path if:
    238 
    239         * the host is provided as part of the base_url
    240         * the request's path isn't under the base path
    241         """
    242         return path.startswith(self.base_url[2]) and not self.base_url[1]
    243 
    244 
    245201def run(addr, port, wsgi_handler, ipv6=False, threading=False):
    246202    server_address = (addr, port)
    247203    if threading:
  • docs/howto/deployment/wsgi/gunicorn.txt

    diff --git a/docs/howto/deployment/wsgi/gunicorn.txt b/docs/howto/deployment/wsgi/gunicorn.txt
    index ce9e54d..13d4043 100644
    a b This provides a few Django-specific niceties:  
    5858* validates installed models
    5959
    6060* allows an ``--adminmedia`` option for passing in the location of the
    61   admin media files, mimicing the behavior of runserver.
     61  admin media files.
    6262
    6363See Gunicorn's `deployment documentation`_ for additional tips on starting and
    6464maintaining the Gunicorn server.
  • docs/man/django-admin.1

    diff --git a/docs/man/django-admin.1 b/docs/man/django-admin.1
    index 1f693b8..730f3a5 100644
    a b Runs this project as a FastCGI application. Requires flup. Use  
    7575.B runfcgi help
    7676for help on the KEY=val pairs.
    7777.TP
    78 .BI "runserver [" "\-\-noreload" "] [" "\-\-nothreading" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-ipv6" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]"
     78.BI "runserver [" "\-\-noreload" "] [" "\-\-nothreading" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-ipv6" "] [" "port|ipaddr:port" "]"
    7979Starts a lightweight Web server for development.
    8080.TP
    8181.BI "shell [" "\-\-plain" "]"
    Enables IPv6 addresses.  
    178178.I \-\-verbosity=VERBOSITY
    179179Verbosity level: 0=minimal output, 1=normal output, 2=all output.
    180180.TP
    181 .I \-\-adminmedia=ADMIN_MEDIA_PATH
    182 Specifies the directory from which to serve admin media when using the development server.
    183 .TP
    184181.I \-\-traceback
    185182By default, django-admin.py will show a simple error message whenever an
    186183error occurs. If you specify this option, django-admin.py  will
  • docs/ref/django-admin.txt

    diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
    index 5ea7280..93844a6 100644
    a b You can provide an IPv6 address surrounded by brackets  
    674674
    675675A hostname containing ASCII-only characters can also be used.
    676676
    677 .. django-admin-option:: --adminmedia
    678 
    679 Use the ``--adminmedia`` option to tell Django where to find the various CSS
    680 and JavaScript files for the Django admin interface. Normally, the development
    681 server serves these files out of the Django source tree magically, but you'd
    682 want to use this if you made any changes to those files for your own site.
    683 
    684 Example usage::
    685 
    686     django-admin.py runserver --adminmedia=/tmp/new-admin-style/
    687 
    688677.. versionchanged:: 1.3
    689678
    690679If the :doc:`staticfiles</ref/contrib/staticfiles>` contrib app is enabled
    691680(default in new projects) the :djadmin:`runserver` command will be overriden
    692 with an own :djadmin:`runserver<staticfiles-runserver>` command which doesn't
    693 have the :djadminopt:`--adminmedia` option due to deprecation.
     681with an own :djadmin:`runserver<staticfiles-runserver>` command.
    694682
    695683.. django-admin-option:: --noreload
    696684
  • tests/regressiontests/admin_widgets/tests.py

    diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py
    index ab6db4d..c1116ba 100644
    a b from . import models  
    2020from .widgetadmin import site as widget_admin_site
    2121
    2222
    23 admin_media_prefix = lambda: {
    24     'ADMIN_MEDIA_PREFIX': "%sadmin/" % settings.STATIC_URL,
     23admin_static_prefix = lambda: {
     24    'ADMIN_STATIC_PREFIX': "%sadmin/" % settings.STATIC_URL,
    2525}
    2626
    2727class AdminFormfieldForDBFieldTests(TestCase):
    class FilteredSelectMultipleWidgetTest(DjangoTestCase):  
    196196        w = widgets.FilteredSelectMultiple('test', False)
    197197        self.assertHTMLEqual(
    198198            conditional_escape(w.render('test', 'test')),
    199             '<select multiple="multiple" name="test" class="selectfilter">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 0, "%(ADMIN_MEDIA_PREFIX)s"); });</script>\n' % admin_media_prefix()
     199            '<select multiple="multiple" name="test" class="selectfilter">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 0, "%(ADMIN_STATIC_PREFIX)s"); });</script>\n' % admin_static_prefix()
    200200        )
    201201
    202202    def test_stacked_render(self):
    203203        w = widgets.FilteredSelectMultiple('test', True)
    204204        self.assertHTMLEqual(
    205205            conditional_escape(w.render('test', 'test')),
    206             '<select multiple="multiple" name="test" class="selectfilterstacked">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 1, "%(ADMIN_MEDIA_PREFIX)s"); });</script>\n' % admin_media_prefix()
     206            '<select multiple="multiple" name="test" class="selectfilterstacked">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 1, "%(ADMIN_STATIC_PREFIX)s"); });</script>\n' % admin_static_prefix()
    207207        )
    208208
    209209class AdminDateWidgetTest(DjangoTestCase):
    class ForeignKeyRawIdWidgetTest(DjangoTestCase):  
    292292        w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)
    293293        self.assertHTMLEqual(
    294294            conditional_escape(w.render('test', band.pk, attrs={})),
    295             '<input type="text" name="test" value="%(bandpk)s" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Linkin Park</strong>' % dict(admin_media_prefix(), bandpk=band.pk)
     295            '<input type="text" name="test" value="%(bandpk)s" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Linkin Park</strong>' % dict(admin_static_prefix(), bandpk=band.pk)
    296296        )
    297297
    298298    def test_relations_to_non_primary_key(self):
    class ForeignKeyRawIdWidgetTest(DjangoTestCase):  
    307307        w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)
    308308        self.assertHTMLEqual(
    309309            w.render('test', core.parent_id, attrs={}),
    310             '<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Apple</strong>' % admin_media_prefix()
     310            '<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Apple</strong>' % admin_static_prefix()
    311311        )
    312312
    313313    def test_fk_related_model_not_in_admin(self):
    class ForeignKeyRawIdWidgetTest(DjangoTestCase):  
    349349        )
    350350        self.assertHTMLEqual(
    351351            w.render('test', child_of_hidden.parent_id, attrs={}),
    352             '<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Hidden</strong>' % admin_media_prefix()
     352            '<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Hidden</strong>' % admin_static_prefix()
    353353        )
    354354
    355355
    class ManyToManyRawIdWidgetTest(DjangoTestCase):  
    365365        w = widgets.ManyToManyRawIdWidget(rel, widget_admin_site)
    366366        self.assertHTMLEqual(
    367367            conditional_escape(w.render('test', [m1.pk, m2.pk], attrs={})),
    368             '<input type="text" name="test" value="%(m1pk)s,%(m2pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="/static/admin/img/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_media_prefix(), m1pk=m1.pk, m2pk=m2.pk)
     368            '<input type="text" name="test" value="%(m1pk)s,%(m2pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="/static/admin/img/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_static_prefix(), m1pk=m1.pk, m2pk=m2.pk)
    369369        )
    370370
    371371        self.assertHTMLEqual(
    372372            conditional_escape(w.render('test', [m1.pk])),
    373             '<input type="text" name="test" value="%(m1pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_media_prefix(), m1pk=m1.pk)
     373            '<input type="text" name="test" value="%(m1pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_static_prefix(), m1pk=m1.pk)
    374374        )
    375375
    376376        self.assertEqual(w._has_changed(None, None), False)
    class HorizontalVerticalFilterSeleniumChromeTests(HorizontalVerticalFilterSeleni  
    691691    webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
    692692
    693693class HorizontalVerticalFilterSeleniumIETests(HorizontalVerticalFilterSeleniumFirefoxTests):
    694     webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
    695  No newline at end of file
     694    webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
  • tests/regressiontests/servers/tests.py

    diff --git a/tests/regressiontests/servers/tests.py b/tests/regressiontests/servers/tests.py
    index d237c83..e226be9 100644
    a b  
    22Tests for django.core.servers.
    33"""
    44import os
    5 from urlparse import urljoin
    65import urllib2
    76
    8 import django
    9 from django.conf import settings
    107from django.core.exceptions import ImproperlyConfigured
    11 from django.test import TestCase, LiveServerTestCase
    12 from django.core.handlers.wsgi import WSGIHandler
    13 from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
     8from django.test import LiveServerTestCase
     9from django.core.servers.basehttp import WSGIServerException
    1410from django.test.utils import override_settings
    1511
    1612from .models import Person
    1713
    18 class AdminMediaHandlerTests(TestCase):
    19 
    20     def setUp(self):
    21         self.admin_media_url = urljoin(settings.STATIC_URL, 'admin/')
    22         self.admin_media_file_path = os.path.abspath(
    23             os.path.join(django.__path__[0], 'contrib', 'admin', 'static', 'admin')
    24         )
    25         self.handler = AdminMediaHandler(WSGIHandler())
    26 
    27     def test_media_urls(self):
    28         """
    29         Tests that URLs that look like absolute file paths after the
    30         settings.STATIC_URL don't turn into absolute file paths.
    31         """
    32         # Cases that should work on all platforms.
    33         data = (
    34             ('%scss/base.css' % self.admin_media_url, ('css', 'base.css')),
    35         )
    36         # Cases that should raise an exception.
    37         bad_data = ()
    38 
    39         # Add platform-specific cases.
    40         if os.sep == '/':
    41             data += (
    42                 # URL, tuple of relative path parts.
    43                 ('%s\\css/base.css' % self.admin_media_url, ('\\css', 'base.css')),
    44             )
    45             bad_data += (
    46                 '%s/css/base.css' % self.admin_media_url,
    47                 '%s///css/base.css' % self.admin_media_url,
    48                 '%s../css/base.css' % self.admin_media_url,
    49             )
    50         elif os.sep == '\\':
    51             bad_data += (
    52                 '%sC:\css/base.css' % self.admin_media_url,
    53                 '%s/\\css/base.css' % self.admin_media_url,
    54                 '%s\\css/base.css' % self.admin_media_url,
    55                 '%s\\\\css/base.css' % self.admin_media_url
    56             )
    57         for url, path_tuple in data:
    58             try:
    59                 output = self.handler.file_path(url)
    60             except ValueError:
    61                 self.fail("Got a ValueError exception, but wasn't expecting"
    62                           " one. URL was: %s" % url)
    63             rel_path = os.path.join(*path_tuple)
    64             desired = os.path.join(self.admin_media_file_path, rel_path)
    65             self.assertEqual(
    66                 os.path.normcase(output), os.path.normcase(desired),
    67                 "Got: %s, Expected: %s, URL was: %s" % (output, desired, url))
    68         for url in bad_data:
    69             try:
    70                 output = self.handler.file_path(url)
    71             except ValueError:
    72                 continue
    73             self.fail('URL: %s should have caused a ValueError exception.'
    74                       % url)
    75 
    7614
    7715TEST_ROOT = os.path.dirname(__file__)
    7816TEST_SETTINGS = {
Back to Top