Permalink
Browse files

Moved default admin from media to django/conf/admin_media, so Django …

…is able to introspect their location, in preparation for #76

git-svn-id: http://code.djangoproject.com/svn/django/trunk@185 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 34f749e commit a7506973af918e177d102328c6db52bc9e0f43b4 @adrianholovaty adrianholovaty committed Jul 18, 2005
Showing with 48 additions and 3 deletions.
  1. +2 −2 django/bin/django-admin.py
  2. 0 {media → django/conf/admin_media}/css/base.css
  3. 0 {media → django/conf/admin_media}/css/changelists.css
  4. 0 {media → django/conf/admin_media}/css/global.css
  5. BIN {media → django/conf/admin_media}/img/admin/arrow-down.gif
  6. BIN {media → django/conf/admin_media}/img/admin/arrow-up.gif
  7. BIN {media → django/conf/admin_media}/img/admin/changelist-bg.gif
  8. BIN {media → django/conf/admin_media}/img/admin/chooser-bg.gif
  9. BIN {media → django/conf/admin_media}/img/admin/chooser_stacked-bg.gif
  10. BIN {media → django/conf/admin_media}/img/admin/default-bg-reverse.gif
  11. BIN {media → django/conf/admin_media}/img/admin/default-bg.gif
  12. BIN {media → django/conf/admin_media}/img/admin/icon-no.gif
  13. BIN {media → django/conf/admin_media}/img/admin/icon-yes.gif
  14. BIN {media → django/conf/admin_media}/img/admin/icon_addlink.gif
  15. BIN {media → django/conf/admin_media}/img/admin/icon_alert.gif
  16. BIN {media → django/conf/admin_media}/img/admin/icon_calendar.gif
  17. BIN {media → django/conf/admin_media}/img/admin/icon_changelink.gif
  18. BIN {media → django/conf/admin_media}/img/admin/icon_clock.gif
  19. BIN {media → django/conf/admin_media}/img/admin/icon_deletelink.gif
  20. BIN {media → django/conf/admin_media}/img/admin/icon_error.gif
  21. BIN {media → django/conf/admin_media}/img/admin/icon_searchbox.png
  22. BIN {media → django/conf/admin_media}/img/admin/icon_success.gif
  23. BIN {media → django/conf/admin_media}/img/admin/nav-bg-grabber.gif
  24. BIN {media → django/conf/admin_media}/img/admin/nav-bg-reverse.gif
  25. BIN {media → django/conf/admin_media}/img/admin/nav-bg.gif
  26. BIN {media → django/conf/admin_media}/img/admin/selector-add.gif
  27. BIN {media → django/conf/admin_media}/img/admin/selector-addall.gif
  28. BIN {media → django/conf/admin_media}/img/admin/selector-remove.gif
  29. BIN {media → django/conf/admin_media}/img/admin/selector-removeall.gif
  30. BIN {media → django/conf/admin_media}/img/admin/selector-search.gif
  31. BIN {media → django/conf/admin_media}/img/admin/selector_stacked-add.gif
  32. BIN {media → django/conf/admin_media}/img/admin/selector_stacked-remove.gif
  33. BIN {media → django/conf/admin_media}/img/admin/tool-left.gif
  34. BIN {media → django/conf/admin_media}/img/admin/tool-left_over.gif
  35. BIN {media → django/conf/admin_media}/img/admin/tool-right.gif
  36. BIN {media → django/conf/admin_media}/img/admin/tool-right_over.gif
  37. BIN {media → django/conf/admin_media}/img/admin/tooltag-add.gif
  38. BIN {media → django/conf/admin_media}/img/admin/tooltag-add_over.gif
  39. BIN {media → django/conf/admin_media}/img/admin/tooltag-arrowright.gif
  40. BIN {media → django/conf/admin_media}/img/admin/tooltag-arrowright_over.gif
  41. 0 {media → django/conf/admin_media}/js/SelectBox.js
  42. 0 {media → django/conf/admin_media}/js/SelectFilter.js
  43. 0 {media → django/conf/admin_media}/js/SelectFilter2.js
  44. 0 {media → django/conf/admin_media}/js/admin/CollapsedFieldsets.js
  45. 0 {media → django/conf/admin_media}/js/admin/DateTimeShortcuts.js
  46. 0 {media → django/conf/admin_media}/js/admin/RelatedObjectLookups.js
  47. 0 {media → django/conf/admin_media}/js/admin/add_calendars.js
  48. 0 {media → django/conf/admin_media}/js/admin/ordering.js
  49. 0 {media → django/conf/admin_media}/js/calendar.js
  50. 0 {media → django/conf/admin_media}/js/core.js
  51. 0 {media → django/conf/admin_media}/js/dateparse.js
  52. 0 {media → django/conf/admin_media}/js/getElementsBySelector.js
  53. 0 {media → django/conf/admin_media}/js/timeparse.js
  54. 0 {media → django/conf/admin_media}/js/urlify.js
  55. +42 −0 django/core/handlers/wsgi.py
  56. +4 −1 setup.py
@@ -365,13 +365,13 @@ def startapp(app_name, directory):
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 = {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -240,3 +240,45 @@ def _get_traceback(self):
"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
View
@@ -13,7 +13,10 @@
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'],
)

0 comments on commit a750697

Please sign in to comment.