On Sat, 2005-11-05 at 09:16 -0500, Kevin Dangoor wrote:
> People don't realize this, but CherryPy's system is a lot more
> flexible than people give it credit for, and I like how CP does not
> require a separate configuration for URLs. Your example here can be
> handled fairly simply:
> 
> class Blog:
>     @turbogears.expose()
>     def default(self, slug):
>         ...do something...
> 
> class Root(controllers.Root):
>     blog = Blog()
> 
> Also, CP 2.2 is going to add back positional parameters handling for
> methods. There's a ticket open to do this in TurboGears, and I may
> just do that as an interim measure until CP 2.2 is out. So, that adds
> this option:
> 
> class Root(controllers.Root):
>     @turbogears.expose()
>     def blog(self, slug):
>         ...do something...
> 
> This would actually allow either of these URLs to work:
> /blog/slug
> 
> /blog?slug=slug


Kevin, adding back positional params will be awesome.  I know you can
currently use default, but you are going to have to create a separate
class for every exposed method or put some sort of dispatch logic into
your Root.default.  I do agree that not having to maintain a separate
URL mapping file is nice and DRY.

Also turbogears.expose validators do not work with positional
parameters.  I've toyed with various fixes to this - my initial thought
was to do introspection on the decorated method, but I think that breaks
when you have stacked decorators like

@turbogears.expose()
@require_group("Admin")
def blog(self, slug):
    ...

Maybe we could require that expose always decorate the method directly?
It makes things a little more fragile, but it would allow expose to
introspect the method it is decorating to get the names of positional
parameters.

We could allow validators to be specified as either a list or a dict,
but what if you want a url like:

http://www.example.com/blog/my_slug_here/?page=2

I'm not sure how you are going to specify the validator list for your
method:

@turbogears.expose()
def blog(self, slug, page=0)
    ... do something here ...

Maybe just have a separate positional_validators argument to expose?



Kind Regards,

Sean Cazzell

Reply via email to