Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1417

Show
Ignore:
Timestamp:
10/28/06 10:31:33
Author:
lawouach
Message:

The RoutesDispatcher? now accepts an extra parameter. If it sets to False (default) the controller and action keys from the Routes matching result dictionary will be removed. If it sets to True they will be kept. In the first case the page handlers will be passed on only the parameters as the default CP dispatcher.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpdispatch.py

    r1398 r1417  
    206206    """A Routes based dispatcher for CherryPy.""" 
    207207     
    208     def __init__(self): 
     208    def __init__(self, full_result=False): 
     209        """ 
     210        Routes dispatcher 
     211 
     212        Set full_result to True if you wish the controller 
     213        and the action to be passed on to the page handler 
     214        parameters. By default they won't be. 
     215        """ 
    209216        import routes 
     217        self.full_result = full_result 
    210218        self.controllers = {} 
    211219        self.mapper = routes.Mapper() 
     
    245253        result = self.mapper.match(path_info) 
    246254        config.mapper_dict = result 
    247         request.params.update(result or {}) 
     255        params = {} 
     256        if result: 
     257            params = result.copy() 
     258        if not self.full_result: 
     259            params.pop('controller', None) 
     260            params.pop('action', None) 
     261        request.params.update(params) 
    248262         
    249263        # Get config for the root object/path. 
     
    270284            last = None 
    271285        for atom in atoms: 
    272             curpath = "/".join((curpath, name)) 
     286            curpath = "/".join((curpath, atom)) 
    273287            if curpath in app.config: 
    274288                merge(app.config[curpath]) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets