Ticket #2557: basehttp-GenerellMediaHandler.diff
File basehttp-GenerellMediaHandler.diff, 2.0 KB (added by , 18 years ago) |
---|
-
django/core/servers/basehttp.py
587 587 return 588 588 sys.stderr.write("[%s] %s\n" % (self.log_date_time_string(), format % args)) 589 589 590 # At compile time, cache the directories to search. 591 from django.conf import settings 592 app_media_dirs = [] 593 for app in settings.INSTALLED_APPS: 594 i = app.rfind('.') 595 if i == -1: 596 m, a = app, None 597 else: 598 m, a = app[:i], app[i+1:] 599 try: 600 if a is None: 601 mod = __import__(m, '', '', []) 602 else: 603 mod = getattr(__import__(m, '', '', [a]), a) 604 except ImportError, e: 605 raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0]) 606 media_dir = os.path.join(os.path.dirname(mod.__file__), 'media') 607 if os.path.isdir(media_dir): 608 app_media_dirs.append(media_dir) 609 610 # It won't change, so convert it to a tuple to save memory. 611 app_media_dirs = tuple(app_media_dirs) 612 590 613 class AdminMediaHandler(object): 591 614 """ 592 615 WSGI middleware that intercepts calls to the admin media directory, as … … 598 621 from django.conf import settings 599 622 import django 600 623 self.application = application 601 self.media_dir = django.__path__[0] + '/contrib/admin/media'602 624 self.media_url = settings.ADMIN_MEDIA_PREFIX 603 625 604 626 def __call__(self, environ, start_response): … … 612 634 613 635 # Find the admin file and serve it up, if it exists and is readable. 614 636 relative_url = environ['PATH_INFO'][len(self.media_url):] 615 file_path = os.path.join(self.media_dir, relative_url) 637 for media_dir in app_media_dirs: 638 file_path = os.path.join(media_dir, relative_url) 639 if os.path.exists(file_path): 640 break 616 641 if not os.path.exists(file_path): 617 642 status = '404 NOT FOUND' 618 643 headers = {'Content-type': 'text/plain'}