Changeset 5133

Show
Ignore:
Timestamp:
08/10/08 17:52:36 (5 months ago)
Author:
mramm
Message:

Subclass of the pylons wsgi app that respects the controller path setup in config.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tg/wsgiapp.py

    r5131 r5133  
    11from pylons.wsgiapp import PylonsApp 
    22 
    3 TGApp = PylonsApp 
     3class 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