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.html tell
> > > >> > 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 |

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

# -*- coding: utf-8 -*-
"""
Global configuration file for TG2-specific settings in classifieds.

This file complements development/deployment.ini.

"""

from tg.configuration import AppConfig, Bunch

import classifieds
from classifieds import model
from classifieds.lib import app_globals, helpers

class ClassifiedsConfig(AppConfig):
    
    def setup_routes(self):
        """Customize routing"""
        from tg import config
        from routes import Mapper
        dir = config['pylons.paths']['controllers']
        map = Mapper(directory=dir,
                     always_scan=config['debug'])
        # Defining our custom routes:
        map.connect('/{action}/{classified:\d+}',
                    controller='root')
        # Required by TurboGears:
        map.connect('*url', controller='root', 
                    action='routes_placeholder')
        config['routes.map'] = map

base_config = ClassifiedsConfig()
base_config.renderers = []

base_config.package = classifieds

#Set the default renderer
base_config.default_renderer = 'genshi'
base_config.renderers.append('genshi')
# if you want raw speed and have installed chameleon.genshi
# you should try to use this renderer instead.
# warning: for the moment chameleon does not handle i18n translations
#base_config.renderers.append('chameleon_genshi')

#Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = classifieds.model
base_config.DBSession = classifieds.model.DBSession

# Configure the authentication backend
base_config.auth_backend = 'sqlalchemy'
base_config.sa_auth.dbsession = model.DBSession
# what is the class you want to use to search for users in the database
base_config.sa_auth.user_class = model.User
# what is the class you want to use to search for groups in the database
base_config.sa_auth.group_class = model.Group
# what is the class you want to use to search for permissions in the database
base_config.sa_auth.permission_class = model.Permission

# override this if you would like to provide a different who plugin for
# managing login and logout of your application
base_config.sa_auth.form_plugin = None

# You may optionally define a page where you want users to be redirected to
# on login:
base_config.sa_auth.post_login_url = '/post_login'

# You may optionally define a page where you want users to be redirected to
# on logout:
base_config.sa_auth.post_logout_url = '/post_logout'

Reply via email to