| 3 | | TGApp = PylonsApp |
|---|
| | 3 | class TGApp(PylonsApp): |
|---|
| | 4 | |
|---|
| | 5 | def find_controller(self, controller): |
|---|
| | 6 | """Locates a controller by attempting to import it then grab |
|---|
| | 7 | the SomeController instance from the imported module. |
|---|
| | 8 | |
|---|
| | 9 | Override this to change how the controller object is found once |
|---|
| | 10 | the URL has been resolved. |
|---|
| | 11 | |
|---|
| | 12 | """ |
|---|
| | 13 | # Check to see if we've cached the class instance for this name |
|---|
| | 14 | if controller in self.controller_classes: |
|---|
| | 15 | return self.controller_classes[controller] |
|---|
| | 16 | |
|---|
| | 17 | # Pull the controllers class name, import controller |
|---|
| | 18 | full_module_name = self.config.paths.controller \ |
|---|
| | 19 | + controller.replace('/', '.') |
|---|
| | 20 | |
|---|
| | 21 | # Hide the traceback here if the import fails (bad syntax and such) |
|---|
| | 22 | __traceback_hide__ = 'before_and_this' |
|---|
| | 23 | |
|---|
| | 24 | __import__(full_module_name) |
|---|
| | 25 | module_name = controller.split('/')[-1] |
|---|
| | 26 | class_name = class_name_from_module_name(module_name) + 'Controller' |
|---|
| | 27 | if self.log_debug: |
|---|
| | 28 | log.debug("Found controller, module: '%s', class: '%s'", |
|---|
| | 29 | full_module_name, class_name) |
|---|
| | 30 | self.controller_classes[controller] = mycontroller = \ |
|---|
| | 31 | getattr(sys.modules[full_module_name], class_name) |
|---|
| | 32 | return mycontroller |
|---|