Fixing the model shortcut in pecan shell.

This commit is contained in:
Ryan Petrello
2012-03-07 15:31:04 -05:00
parent 3857c3e2cd
commit 63b9ad6948

View File

@@ -31,8 +31,7 @@ class ShellCommand(Command):
locs['wsgiapp'] = app
locs['app'] = TestApp(app)
# find the model for the app
model = getattr(app, 'model', None)
model = self.load_model(app.config)
if model:
locs['model'] = model
@@ -65,3 +64,10 @@ class ShellCommand(Command):
except ImportError:
pass
shell.interact(shell_banner + banner)
def load_model(self, config):
for package_name in getattr(config.app, 'modules', []):
module = __import__(package_name, fromlist=['model'])
if hasattr(module, 'model'):
return module.model
return None