Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #73 (closed defect: fixed)

Opened 14 years ago

Last modified 12 years ago

Support for positional parameters

Reported by: kevin Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TurboGears Version:
Severity: normal Keywords:


It would be convenient to be able to do positional parameters for any method, rather than having to use a default method. CherryPy? includes a PositionalParametersAware? class (in lib.cptools) that may point the way to doing this. It shouldn't be difficult.

Something like this:

def index(self, year, month, day):
    ...do stuff...

which can be called by /YEAR/MONTH/DAY

The trick to implementing this will be validators.

Change History

comment:1 Changed 14 years ago by michele

IMO if someone wants positional parameters (and personally I would like to) then he wants to use them for every method of his app, so having to modify every expose to add positional=True it's not the best thing, right? And what about the URL generation function, shouldn't it be aware that the method uses positional parameters?

Disclaimer: I'm not a python/cherrypy expert.

What about a global setting in the configuration file like this:

usePositionalParameters = [True|False]

Then in turbogears.controllers we can put something like this:

if usePositionalParameters:
   from cherrypy.lib.cptools import PositionalParametersAware as object

class Controller(object):
class Root(Controller):

the URL generation function should also check for the global setting to decide the type of URL to return and it should also be called with parameters in the right order.

Assuming that every controller class extends the base class Controller shouldn't this just work? I can't comment on the validators problems.

As a side note I think that for TG 0.9 you should really suggest on the doc (since you can't enforce this) that every controller class should be derived from Controller (as my example on ticket #81). This is a small change for existing applications now, but in the future you may be able to add new feature without the fear of breaking existing code (and hopefully for TG this would means a large number of applications ;-)).

Probably I'm totally wrong... time to sleep for me here.

comment:2 Changed 14 years ago by michele

Ok, I just tried to do this on my local install:

from cherrypy.lib.cptools import PositionalParametersAware as object

class Controller(object):

and it works.

But I'm sure overriding object in this way it's not the best practise.

comment:3 Changed 14 years ago by fumanchu@…

CherryPy? 2.2 ( rev 786) now allows positional params on all methods.

comment:4 Changed 14 years ago by kevin

  • Milestone set to 0.9

We should look at how easy it would be to implement in expose as a stop gap, before CP2.2. I'm going to target this for 0.9, but it will slip if it proves difficult.

comment:5 Changed 14 years ago by anonymous

  • Summary changed from implement positional parameters in expose to Support for positional parameters

comment:6 Changed 14 years ago by kevin

  • Status changed from new to closed
  • Resolution set to fixed

added in [427]

Note: See TracTickets for help on using tickets.