Fixed #2600 -- Added an option to allow serving admin media from a custom path

with dev server. Thanks, adurdin@gmail.com.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3811 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2006-09-24 08:17:47 +00:00
parent 35a13d4b6b
commit ff47dc6ba0
3 changed files with 16 additions and 8 deletions

View File

@ -42,6 +42,7 @@ And here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS --
people who have submitted patches, reported bugs, added translations, helped people who have submitted patches, reported bugs, added translations, helped
answer newbie questions, and generally made Django that much better: answer newbie questions, and generally made Django that much better:
adurdin@gmail.com
akaihola akaihola
Andreas Andreas
ant9000@netwise.it ant9000@netwise.it

View File

@ -1045,7 +1045,7 @@ def _check_for_validation_errors(app=None):
sys.stderr.write(s.read()) sys.stderr.write(s.read())
sys.exit(1) sys.exit(1)
def runserver(addr, port, use_reloader=True): def runserver(addr, port, use_reloader=True, admin_media_dir=''):
"Starts a lightweight Web server for development." "Starts a lightweight Web server for development."
from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
from django.core.handlers.wsgi import WSGIHandler from django.core.handlers.wsgi import WSGIHandler
@ -1063,7 +1063,10 @@ def runserver(addr, port, use_reloader=True):
print "Development server is running at http://%s:%s/" % (addr, port) print "Development server is running at http://%s:%s/" % (addr, port)
print "Quit the server with %s." % quit_command print "Quit the server with %s." % quit_command
try: try:
run(addr, int(port), AdminMediaHandler(WSGIHandler())) import django
path = admin_media_dir or django.__path__[0] + '/contrib/admin/media'
handler = AdminMediaHandler(WSGIHandler(), path)
run(addr, int(port), handler)
except WSGIServerException, e: except WSGIServerException, e:
# Use helpful error messages instead of ugly tracebacks. # Use helpful error messages instead of ugly tracebacks.
ERRORS = { ERRORS = {
@ -1084,7 +1087,7 @@ def runserver(addr, port, use_reloader=True):
autoreload.main(inner_run) autoreload.main(inner_run)
else: else:
inner_run() inner_run()
runserver.args = '[--noreload] [optional port number, or ipaddr:port]' runserver.args = '[--noreload] [--adminmedia=ADMIN_MEDIA_PATH] [optional port number, or ipaddr:port]'
def createcachetable(tablename): def createcachetable(tablename):
"Creates the table needed to use the SQL cache backend" "Creates the table needed to use the SQL cache backend"
@ -1270,7 +1273,8 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
help='Tells Django to NOT use the auto-reloader when running the development server.') help='Tells Django to NOT use the auto-reloader when running the development server.')
parser.add_option('--verbosity', action='store', dest='verbosity', default='2', parser.add_option('--verbosity', action='store', dest='verbosity', default='2',
type='choice', choices=['0', '1', '2'], type='choice', choices=['0', '1', '2'],
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
parser.add_option('--adminmedia', dest='admin_media_path', default='', help='Lets you manually specify the directory to serve admin media from when running the development server.'),
options, args = parser.parse_args(argv[1:]) options, args = parser.parse_args(argv[1:])
@ -1334,7 +1338,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
addr, port = args[1].split(':') addr, port = args[1].split(':')
except ValueError: except ValueError:
addr, port = '', args[1] addr, port = '', args[1]
action_mapping[action](addr, port, options.use_reloader) action_mapping[action](addr, port, options.use_reloader, options.admin_media_path)
elif action == 'runfcgi': elif action == 'runfcgi':
action_mapping[action](args[1:]) action_mapping[action](args[1:])
else: else:

View File

@ -594,11 +594,14 @@ class AdminMediaHandler(object):
Use this ONLY LOCALLY, for development! This hasn't been tested for Use this ONLY LOCALLY, for development! This hasn't been tested for
security and is not super efficient. security and is not super efficient.
""" """
def __init__(self, application): def __init__(self, application, media_dir = None):
from django.conf import settings from django.conf import settings
import django
self.application = application self.application = application
self.media_dir = django.__path__[0] + '/contrib/admin/media' if not media_dir:
import django
self.media_dir = django.__path__[0] + '/contrib/admin/media'
else:
self.media_dir = media_dir
self.media_url = settings.ADMIN_MEDIA_PREFIX self.media_url = settings.ADMIN_MEDIA_PREFIX
def __call__(self, environ, start_response): def __call__(self, environ, start_response):