diff --git a/django/bin/django-admin.py b/django/bin/django-admin.py index 96738461b1d..2bbc03764c9 100755 --- a/django/bin/django-admin.py +++ b/django/bin/django-admin.py @@ -365,13 +365,13 @@ startapp.args = "[appname]" def runserver(port): "Starts a lightweight Web server for development." from django.core.servers.basehttp import run, WSGIServerException - from django.core.handlers.wsgi import WSGIHandler + from django.core.handlers.wsgi import AdminMediaHandler, WSGIHandler if not port.isdigit(): sys.stderr.write("Error: %r is not a valid port number.\n" % port) sys.exit(1) print "Starting server on port %s. Go to http://127.0.0.1:%s/ for Django." % (port, port) try: - run(int(port), WSGIHandler()) + run(int(port), AdminMediaHandler(WSGIHandler())) except WSGIServerException, e: # Use helpful error messages instead of ugly tracebacks. ERRORS = { diff --git a/media/css/base.css b/django/conf/admin_media/css/base.css similarity index 100% rename from media/css/base.css rename to django/conf/admin_media/css/base.css diff --git a/media/css/changelists.css b/django/conf/admin_media/css/changelists.css similarity index 100% rename from media/css/changelists.css rename to django/conf/admin_media/css/changelists.css diff --git a/media/css/global.css b/django/conf/admin_media/css/global.css similarity index 100% rename from media/css/global.css rename to django/conf/admin_media/css/global.css diff --git a/media/img/admin/arrow-down.gif b/django/conf/admin_media/img/admin/arrow-down.gif similarity index 100% rename from media/img/admin/arrow-down.gif rename to django/conf/admin_media/img/admin/arrow-down.gif diff --git a/media/img/admin/arrow-up.gif b/django/conf/admin_media/img/admin/arrow-up.gif similarity index 100% rename from media/img/admin/arrow-up.gif rename to django/conf/admin_media/img/admin/arrow-up.gif diff --git a/media/img/admin/changelist-bg.gif b/django/conf/admin_media/img/admin/changelist-bg.gif similarity index 100% rename from media/img/admin/changelist-bg.gif rename to django/conf/admin_media/img/admin/changelist-bg.gif diff --git a/media/img/admin/chooser-bg.gif b/django/conf/admin_media/img/admin/chooser-bg.gif similarity index 100% rename from media/img/admin/chooser-bg.gif rename to django/conf/admin_media/img/admin/chooser-bg.gif diff --git a/media/img/admin/chooser_stacked-bg.gif b/django/conf/admin_media/img/admin/chooser_stacked-bg.gif similarity index 100% rename from media/img/admin/chooser_stacked-bg.gif rename to django/conf/admin_media/img/admin/chooser_stacked-bg.gif diff --git a/media/img/admin/default-bg-reverse.gif b/django/conf/admin_media/img/admin/default-bg-reverse.gif similarity index 100% rename from media/img/admin/default-bg-reverse.gif rename to django/conf/admin_media/img/admin/default-bg-reverse.gif diff --git a/media/img/admin/default-bg.gif b/django/conf/admin_media/img/admin/default-bg.gif similarity index 100% rename from media/img/admin/default-bg.gif rename to django/conf/admin_media/img/admin/default-bg.gif diff --git a/media/img/admin/icon-no.gif b/django/conf/admin_media/img/admin/icon-no.gif similarity index 100% rename from media/img/admin/icon-no.gif rename to django/conf/admin_media/img/admin/icon-no.gif diff --git a/media/img/admin/icon-yes.gif b/django/conf/admin_media/img/admin/icon-yes.gif similarity index 100% rename from media/img/admin/icon-yes.gif rename to django/conf/admin_media/img/admin/icon-yes.gif diff --git a/media/img/admin/icon_addlink.gif b/django/conf/admin_media/img/admin/icon_addlink.gif similarity index 100% rename from media/img/admin/icon_addlink.gif rename to django/conf/admin_media/img/admin/icon_addlink.gif diff --git a/media/img/admin/icon_alert.gif b/django/conf/admin_media/img/admin/icon_alert.gif similarity index 100% rename from media/img/admin/icon_alert.gif rename to django/conf/admin_media/img/admin/icon_alert.gif diff --git a/media/img/admin/icon_calendar.gif b/django/conf/admin_media/img/admin/icon_calendar.gif similarity index 100% rename from media/img/admin/icon_calendar.gif rename to django/conf/admin_media/img/admin/icon_calendar.gif diff --git a/media/img/admin/icon_changelink.gif b/django/conf/admin_media/img/admin/icon_changelink.gif similarity index 100% rename from media/img/admin/icon_changelink.gif rename to django/conf/admin_media/img/admin/icon_changelink.gif diff --git a/media/img/admin/icon_clock.gif b/django/conf/admin_media/img/admin/icon_clock.gif similarity index 100% rename from media/img/admin/icon_clock.gif rename to django/conf/admin_media/img/admin/icon_clock.gif diff --git a/media/img/admin/icon_deletelink.gif b/django/conf/admin_media/img/admin/icon_deletelink.gif similarity index 100% rename from media/img/admin/icon_deletelink.gif rename to django/conf/admin_media/img/admin/icon_deletelink.gif diff --git a/media/img/admin/icon_error.gif b/django/conf/admin_media/img/admin/icon_error.gif similarity index 100% rename from media/img/admin/icon_error.gif rename to django/conf/admin_media/img/admin/icon_error.gif diff --git a/media/img/admin/icon_searchbox.png b/django/conf/admin_media/img/admin/icon_searchbox.png similarity index 100% rename from media/img/admin/icon_searchbox.png rename to django/conf/admin_media/img/admin/icon_searchbox.png diff --git a/media/img/admin/icon_success.gif b/django/conf/admin_media/img/admin/icon_success.gif similarity index 100% rename from media/img/admin/icon_success.gif rename to django/conf/admin_media/img/admin/icon_success.gif diff --git a/media/img/admin/nav-bg-grabber.gif b/django/conf/admin_media/img/admin/nav-bg-grabber.gif similarity index 100% rename from media/img/admin/nav-bg-grabber.gif rename to django/conf/admin_media/img/admin/nav-bg-grabber.gif diff --git a/media/img/admin/nav-bg-reverse.gif b/django/conf/admin_media/img/admin/nav-bg-reverse.gif similarity index 100% rename from media/img/admin/nav-bg-reverse.gif rename to django/conf/admin_media/img/admin/nav-bg-reverse.gif diff --git a/media/img/admin/nav-bg.gif b/django/conf/admin_media/img/admin/nav-bg.gif similarity index 100% rename from media/img/admin/nav-bg.gif rename to django/conf/admin_media/img/admin/nav-bg.gif diff --git a/media/img/admin/selector-add.gif b/django/conf/admin_media/img/admin/selector-add.gif similarity index 100% rename from media/img/admin/selector-add.gif rename to django/conf/admin_media/img/admin/selector-add.gif diff --git a/media/img/admin/selector-addall.gif b/django/conf/admin_media/img/admin/selector-addall.gif similarity index 100% rename from media/img/admin/selector-addall.gif rename to django/conf/admin_media/img/admin/selector-addall.gif diff --git a/media/img/admin/selector-remove.gif b/django/conf/admin_media/img/admin/selector-remove.gif similarity index 100% rename from media/img/admin/selector-remove.gif rename to django/conf/admin_media/img/admin/selector-remove.gif diff --git a/media/img/admin/selector-removeall.gif b/django/conf/admin_media/img/admin/selector-removeall.gif similarity index 100% rename from media/img/admin/selector-removeall.gif rename to django/conf/admin_media/img/admin/selector-removeall.gif diff --git a/media/img/admin/selector-search.gif b/django/conf/admin_media/img/admin/selector-search.gif similarity index 100% rename from media/img/admin/selector-search.gif rename to django/conf/admin_media/img/admin/selector-search.gif diff --git a/media/img/admin/selector_stacked-add.gif b/django/conf/admin_media/img/admin/selector_stacked-add.gif similarity index 100% rename from media/img/admin/selector_stacked-add.gif rename to django/conf/admin_media/img/admin/selector_stacked-add.gif diff --git a/media/img/admin/selector_stacked-remove.gif b/django/conf/admin_media/img/admin/selector_stacked-remove.gif similarity index 100% rename from media/img/admin/selector_stacked-remove.gif rename to django/conf/admin_media/img/admin/selector_stacked-remove.gif diff --git a/media/img/admin/tool-left.gif b/django/conf/admin_media/img/admin/tool-left.gif similarity index 100% rename from media/img/admin/tool-left.gif rename to django/conf/admin_media/img/admin/tool-left.gif diff --git a/media/img/admin/tool-left_over.gif b/django/conf/admin_media/img/admin/tool-left_over.gif similarity index 100% rename from media/img/admin/tool-left_over.gif rename to django/conf/admin_media/img/admin/tool-left_over.gif diff --git a/media/img/admin/tool-right.gif b/django/conf/admin_media/img/admin/tool-right.gif similarity index 100% rename from media/img/admin/tool-right.gif rename to django/conf/admin_media/img/admin/tool-right.gif diff --git a/media/img/admin/tool-right_over.gif b/django/conf/admin_media/img/admin/tool-right_over.gif similarity index 100% rename from media/img/admin/tool-right_over.gif rename to django/conf/admin_media/img/admin/tool-right_over.gif diff --git a/media/img/admin/tooltag-add.gif b/django/conf/admin_media/img/admin/tooltag-add.gif similarity index 100% rename from media/img/admin/tooltag-add.gif rename to django/conf/admin_media/img/admin/tooltag-add.gif diff --git a/media/img/admin/tooltag-add_over.gif b/django/conf/admin_media/img/admin/tooltag-add_over.gif similarity index 100% rename from media/img/admin/tooltag-add_over.gif rename to django/conf/admin_media/img/admin/tooltag-add_over.gif diff --git a/media/img/admin/tooltag-arrowright.gif b/django/conf/admin_media/img/admin/tooltag-arrowright.gif similarity index 100% rename from media/img/admin/tooltag-arrowright.gif rename to django/conf/admin_media/img/admin/tooltag-arrowright.gif diff --git a/media/img/admin/tooltag-arrowright_over.gif b/django/conf/admin_media/img/admin/tooltag-arrowright_over.gif similarity index 100% rename from media/img/admin/tooltag-arrowright_over.gif rename to django/conf/admin_media/img/admin/tooltag-arrowright_over.gif diff --git a/media/js/SelectBox.js b/django/conf/admin_media/js/SelectBox.js similarity index 100% rename from media/js/SelectBox.js rename to django/conf/admin_media/js/SelectBox.js diff --git a/media/js/SelectFilter.js b/django/conf/admin_media/js/SelectFilter.js similarity index 100% rename from media/js/SelectFilter.js rename to django/conf/admin_media/js/SelectFilter.js diff --git a/media/js/SelectFilter2.js b/django/conf/admin_media/js/SelectFilter2.js similarity index 100% rename from media/js/SelectFilter2.js rename to django/conf/admin_media/js/SelectFilter2.js diff --git a/media/js/admin/CollapsedFieldsets.js b/django/conf/admin_media/js/admin/CollapsedFieldsets.js similarity index 100% rename from media/js/admin/CollapsedFieldsets.js rename to django/conf/admin_media/js/admin/CollapsedFieldsets.js diff --git a/media/js/admin/DateTimeShortcuts.js b/django/conf/admin_media/js/admin/DateTimeShortcuts.js similarity index 100% rename from media/js/admin/DateTimeShortcuts.js rename to django/conf/admin_media/js/admin/DateTimeShortcuts.js diff --git a/media/js/admin/RelatedObjectLookups.js b/django/conf/admin_media/js/admin/RelatedObjectLookups.js similarity index 100% rename from media/js/admin/RelatedObjectLookups.js rename to django/conf/admin_media/js/admin/RelatedObjectLookups.js diff --git a/media/js/admin/add_calendars.js b/django/conf/admin_media/js/admin/add_calendars.js similarity index 100% rename from media/js/admin/add_calendars.js rename to django/conf/admin_media/js/admin/add_calendars.js diff --git a/media/js/admin/ordering.js b/django/conf/admin_media/js/admin/ordering.js similarity index 100% rename from media/js/admin/ordering.js rename to django/conf/admin_media/js/admin/ordering.js diff --git a/media/js/calendar.js b/django/conf/admin_media/js/calendar.js similarity index 100% rename from media/js/calendar.js rename to django/conf/admin_media/js/calendar.js diff --git a/media/js/core.js b/django/conf/admin_media/js/core.js similarity index 100% rename from media/js/core.js rename to django/conf/admin_media/js/core.js diff --git a/media/js/dateparse.js b/django/conf/admin_media/js/dateparse.js similarity index 100% rename from media/js/dateparse.js rename to django/conf/admin_media/js/dateparse.js diff --git a/media/js/getElementsBySelector.js b/django/conf/admin_media/js/getElementsBySelector.js similarity index 100% rename from media/js/getElementsBySelector.js rename to django/conf/admin_media/js/getElementsBySelector.js diff --git a/media/js/timeparse.js b/django/conf/admin_media/js/timeparse.js similarity index 100% rename from media/js/timeparse.js rename to django/conf/admin_media/js/timeparse.js diff --git a/media/js/urlify.js b/django/conf/admin_media/js/urlify.js similarity index 100% rename from media/js/urlify.js rename to django/conf/admin_media/js/urlify.js diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index d4db06cbc20..5006272685e 100644 --- a/django/core/handlers/wsgi.py +++ b/django/core/handlers/wsgi.py @@ -240,3 +240,45 @@ class WSGIHandler: "Helper function to return the traceback as a string" import sys, traceback return '\n'.join(traceback.format_exception(*sys.exc_info())) + +class AdminMediaHandler: + """ + WSGI middleware that intercepts calls to the admin media directory, as + defined by the ADMIN_MEDIA_PREFIX setting, and serves those images. + Use this ONLY LOCALLY, for development! This hasn't been tested for + security and is not super efficient. + """ + def __init__(self, application): + from django.conf import settings + import django + self.application = application + self.media_dir = django.__path__[0] + '/conf/admin_templates' + self.media_url = settings.ADMIN_MEDIA_PREFIX + + def __call__(self, environ, start_response): + import os.path + + # Ignore requests that aren't under ADMIN_MEDIA_PREFIX. + if not environ['PATH_INFO'].startswith(self.media_url): + return self.application(environ, start_response) + + # Find the admin file and serve it up, if it exists and is readable. + file_path = os.path.join(self.media_dir, environ['PATH_INFO'][1:]) + if not os.path.exists(file_path): + status = '404 NOT FOUND' + headers = {'Content-type': 'text/plain'} + output = ['Page not found: %s' % file_path] + else: + try: + fp = open(file_path, 'r') + except IOError: + status = '401 UNAUTHORIZED' + headers = {'Content-type': 'text/plain'} + output = ['Permission denied: %s' % file_path] + else: + status = '200 OK' + headers = {} + output = [fp.read()] + fp.close() + start_response(status, headers.items()) + return output diff --git a/setup.py b/setup.py index 1824dfd1ffc..50ee6ff021d 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,10 @@ setup( license = 'BSD', packages = find_packages(), package_data = { - 'django.conf': ['admin_templates/*.html', 'admin_templates/doc/*.html'], + 'django.conf': ['admin_templates/*.html', 'admin_templates/doc/*.html', + 'admin_media/css/*.css', 'admin_media/img/admin/*.gif', + 'admin_media/img/admin/*.png', 'admin_media/js/*.js', + 'admin_media/js/admin/*js'], }, scripts = ['django/bin/django-admin.py'], )