Hello Gustavo,
I tried it but it didn't work for me. Maybe I got the URL syntax
wrong. What URLs map to your custom routes? Also, from reading the
Routes manual I got the impression that variables are words with a
colon in the end (e.g 'prefix:'), but your routes look like regular
expressions.

Thanks, Carl

On Mar 13, 9:07 pm, Gustavo Narea <[email protected]> wrote:
> Hello,
>
> I've had no problem while using custom routes; attached is the app_cfg.py file
> of a project which uses them. I didn't have to deal with DecoratedControllers
> or something else, just what you see in the attached file.
>
> Cheers.
>
> On Friday March 13, 2009 20:40:58 Carl wrote:
>
> > Ok. I followed the code through the internals. I created a separate
> > controller derived from DecoratedController and updates the
> > setup_routes() function. The routing works just fine and returns
> > eventually my new controller. Then we get into the actuall object
> > dispatch and it looks like the TG piece and the Pylons piece don't
> > agree exactly on what's going on.
>
> > - In pylons/controllers/core.py the __call__() method of the
> > WSGIController is called
> > - The __call__() method calls _inspect_call() with the __before__
> > attribute, which is a function
> > - The _inspect_call() method after a lot of arg checks and other stuff
> > calls the _perform_call with the __before__ attribute
>
> > - The _inspect_call() method is implemented by TG proper in
> > tg.controllers.DecoratedController. This expects the passed in func
> > object to have a 'decoration' attribute, but the __before__ function
> > passed by Pylons have no such attribute, so we get AttributeError and
> > everything blows up.
>
> > Does it ring a bell? I can't figure out all the implicit assumptions
> > and expectations in the code. I can't even tell if there is a bug or
> > if I'm doing something wrong/missing some configuration step.
>
> > Thanks, Carl
>
> > On Mar 13, 11:50 am, Carl <[email protected]> wrote:
> > > I'm using the latest TurboGears2 2.0b7 (according to paster tginfo). I
> > > also did:
>
> > > easy_install -U -ihttp://www.turbogears.org/2.0/downloads/current/index
> > > tg.devtools
>
> > > and it told me I already have the latest. I'll try routing to a
> > > different controller.
>
> > > Thanks, Carl
>
> > > On Mar 13, 10:49 am, Mark Ramm <[email protected]> wrote:
> > > > I think there was a bug with __before__  and the decoration object
> > > > that has been fixed in the last beta, what version of tg2 are you
> > > > using (you can check with paster tginfo).
>
> > > > I have not tried making the RootController into a decorated
> > > > controller, I'd try making a new controller and routing to that.   I
> > > > won't have time to make a doc this afternoon, but I can try to look at
> > > > it tomorrow if you don't get it working before then.
>
> > > > --Mark
>
> > > > On Fri, Mar 13, 2009 at 1:01 PM, Carl <[email protected]> wrote:
> > > > > Mark,
> > > > > Thanks for the quick response. It didn't work though. My
> > > > > RootController now subclasses tg.controllers.DecoratedController and
> > > > > I get the following error even onhttp://localhost:8080/(theroot):
>
> > > > > Module tg.controllers:125 in _perform_call
>
> > > > >>>  controller.decoration.run_hooks('before_validate', remainder,
>
> > > > > AttributeError: 'function' object has no attribute 'decoration'
>
> > > > > The code expects 'controller' to be an object with a 'decoration'
> > > > > attribute, but in my case the controller is the __before__ method of
>
> > > > > RootController:
> > > > >>>> controller
>
> > > > > <bound method RootController.__before__ of
> > > > > <nine.controllers.root.RootController object at 0x99a3d0>>
>
> > > > > Is it possible to post a fully working TG2 custom routes example? It
> > > > > doesn't even have to be the entire project just the differences from
> > > > > a standard quickstarted project.
>
> > > > > Thanks, Carl
>
> > > > > On Mar 13, 7:40 am, Mark Ramm <[email protected]> wrote:
> > > > >> Yea, those docs are missing some important details.
>
> > > > >> One think you do need to know is that the
> > > > >> TGController/ObjectDispatchController expects to be routed to for
> > > > >> object dispatch, not for a final page.
>
> > > > >> So you want to use DecoratedController when defining your own custom
> > > > >> routes.
>
> > > > >> All of this should go on the RoutesIntegration page.
>
> > > > >> --Mark
>
> > > > >> On Fri, Mar 13, 2009 at 6:23 AM, Carl <[email protected]> wrote:
> > > > >> > Hi,
> > > > >> > I'm trying to do custom routes with TG2 and failing so far. The
> > > > >> > instructions
> > > > >> > inhttp://turbogears.org/2.0/docs/main/RoutesIntegration.htmltell
> > > > >> > you to:
>
> > > > >> > "you can easily do that, just by providing your own function to
> > > > >> > set up the routes map. You can update the routes defaults by
> > > > >> > overriding the setup_routes method of the base_config object in
> > > > >> > app_cfg.py."
>
> > > > >> > Well, it's not that clear . setup routes() is a method of
> > > > >> > AppConfig. If you just implement your own function in app_cfg.py
> > > > >> > it is never called. You can subclass AppConfig and provide your
> > > > >> > own setup_routes() method or you can create a custom
> > > > >> > setup_routes() function and assign it to the original AppConfig
> > > > >> > before you instantiate base_config:
>
> > > > >> > AppConfig.setup_routes = custom_setup_routes
> > > > >> > base_config = AppConfig()
>
> > > > >> > You will also need to import a bunch of stuff from
> > > > >> > tg.configuration such as Mapper and config.
>
> > > > >> > Once, I got that part right and my custom_setup_routes function
> > > > >> > was actually called, it just did,'t work. I can't even get a
> > > > >> > simple hard- coded path to work. Here is my custom_setup_routes()
> > > > >> > function:
>
> > > > >> > def custom_setup_routes(self):
> > > > >> >    """Setup the default TG2 routes
>
> > > > >> >    Override this and set up your own routes maps if you want to
> > > > >> > use routes.
> > > > >> >    """
> > > > >> >    #from dbgp.client import brk; brk(port=9011)
> > > > >> >    map = Mapper(directory=config['pylons.paths']['controllers'],
> > > > >> >                always_scan=config['debug'])
>
> > > > >> >    map.connect('prefix/foo', controller='root', action='foo')
>
> > > > >> >    # Setup a default route for the root of object dispatch
> > > > >> >    map.connect('*url', controller='root',
> > > > >> > action='routes_placeholder')
>
> > > > >> >    config['routes.map'] = map
>
> > > > >> > I expect that the /prefix/foo URL will result in a call to the
> > > > >> > foo() method on my RootController, but it doesn't. The standard
> > > > >> > object dospatch works just fine, so /foo does get to my foo()
> > > > >> > method.
>
> > > > >> > Can someone tell me what I'm doing wrong and/or explain how to
> > > > >> > debug routing and/or show a full-fledged example of custom routes
> > > > >> > in TG2?
>
> > > > >> > Thanks, Carl
>
> > > > >> --
> > > > >> Mark Ramm-Christensen
> > > > >> email: mark at compoundthinking dot com
> > > > >> blog:www.compoundthinking.com/blog
>
> > > > --
> > > > Mark Ramm-Christensen
> > > > email: mark at compoundthinking dot com
> > > > blog:www.compoundthinking.com/blog
>
> --
> Gustavo Narea <xri://=Gustavo>.
> | Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |
>
>  app_cfg.py
> 2KViewDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to