Fixed #5082 -- Enabled tab completion in 'django-admin.py shell' for objects that were imported into the global namespace at runtime. Thanks, dusk@woofle.net

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5809 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-08-06 05:04:27 +00:00
parent 89d4a56594
commit e301d8992c
2 changed files with 8 additions and 2 deletions

View File

@ -96,6 +96,7 @@ answer newbie questions, and generally made Django that much better:
Maximillian Dornseif <md@hudora.de> Maximillian Dornseif <md@hudora.de>
Jeremy Dunck <http://dunck.us/> Jeremy Dunck <http://dunck.us/>
Andrew Durdin <adurdin@gmail.com> Andrew Durdin <adurdin@gmail.com>
dusk@woofle.net
Andy Dustman <farcepest@gmail.com> Andy Dustman <farcepest@gmail.com>
Clint Ecker Clint Ecker
enlight enlight

View File

@ -1300,6 +1300,10 @@ def run_shell(use_plain=False):
shell.mainloop() shell.mainloop()
except ImportError: except ImportError:
import code import code
# Set up a dictionary to serve as the environment for the shell, so
# that tab completion works on objects that are imported at runtime.
# See ticket 5082.
imported_objects = {}
try: # Try activating rlcompleter, because it's handy. try: # Try activating rlcompleter, because it's handy.
import readline import readline
except ImportError: except ImportError:
@ -1308,8 +1312,9 @@ def run_shell(use_plain=False):
# We don't have to wrap the following import in a 'try', because # We don't have to wrap the following import in a 'try', because
# we already know 'readline' was imported successfully. # we already know 'readline' was imported successfully.
import rlcompleter import rlcompleter
readline.set_completer(rlcompleter.Completer(imported_objects).complete)
readline.parse_and_bind("tab:complete") readline.parse_and_bind("tab:complete")
code.interact() code.interact(local=imported_objects)
run_shell.args = '[--plain]' run_shell.args = '[--plain]'
def dbshell(): def dbshell():