Re: [web2py] default function in a non default controller with args - routing
Right now using the Parameter-based system for routing if we want to define different default_function for each controller we must set a list of all controllers, and then a dictionary with a list of all functions in each controller. blog=dict( controllers=['posts', 'comments'], functions=dict( posts=['list', 'create', 'show', 'edit', 'delete'], comments=['list', 'create', 'show', 'edit', 'delete'], ), default_controller='posts', default_function=dict( posts='list', comments='show', ) ), Why is this truly necessary? Shouldn't we just set the default_controller and default_function for each controller like bellow? blog=dict( default_controller='posts', default_function=dict( posts='list', comments='show', ) ), It would save lots of time, because every time you add a new controller or function you have to set it in routes and restart the server. And if you have lots of functions, and you access them with .json extension you also have to set those on the list like 'create.json' On Tuesday, July 10, 2012 5:05:44 PM UTC+1, Jonathan Lundell wrote: On 10 Jul 2012, at 6:14 AM, Anthony wrote: Thanks Anthony and Jonathan. It works! It would be nice to have this routing documentation updated in the online book. +1 For now, there's quite a bit in the routers.example.py file (including the detail about making functions a dictionary of lists). One reason that the documentation is more up to date in the example file is that it tracks the relevant version. As opposed to the book, where one doesn't want to change the docs until the changes make it to stable. -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] default function in a non default controller with args - routing
Thanks Anthony and Jonathan. It works! It would be nice to have this routing documentation updated in the online book. On Monday, July 9, 2012 10:58:22 PM UTC+1, Jonathan Lundell wrote: On 9 Jul 2012, at 1:29 PM, Francisco Costa wrote: I'm using the Parameter-based system for routing In my routes.py I have this routers = dict( # base router BASE = dict( applications = ['admin', 'app', 'blog'], default_application = 'app', map_hyphen = True, domains = { 'blog.domain.com' : 'blog', 'domain.com' : 'app' }, ), app = dict( controllers = ['default', 'user'], functions = ['index', 'show', 'list'], default_controller = 'default', default_function = dict(default='index', user='show') ), blog = dict( default_controller = 'default', ), ) When I go to http://localhost/user/john i get this: invalid function (user/john) I would like it to map it to http://localhost/user/show/john So it is possible to pass args to a default function in a non default controller without the name of the function? Try specifying functions as a dict of lists keyed by controller names, and include and entry for user. Something like app = dict( ... functions = dict( default = [ list of functions], user = [ list of functions ], ). ... One other thing to pay attention to is that by default there's a function app/default/user that manages your auth object. The router will do the right thing, but there may be some omissions that it won't be able to do because the conflict creates an ambiguity. In particular, the router can normally shorten /app/default/user/whatever to /user/whatever, but it can't do that if you have a function named user. You can work around that by renaming your controller, or by renaming the auth-support function and telling Auth: auth = Auth(... function='somethingotherthanuser'...)
Re: [web2py] default function in a non default controller with args - routing
Thanks Anthony and Jonathan. It works! It would be nice to have this routing documentation updated in the online book. +1 For now, there's quite a bit in the routers.example.py file (including the detail about making functions a dictionary of lists). Anthony
Re: [web2py] default function in a non default controller with args - routing
On 10 Jul 2012, at 6:14 AM, Anthony wrote: Thanks Anthony and Jonathan. It works! It would be nice to have this routing documentation updated in the online book. +1 For now, there's quite a bit in the routers.example.py file (including the detail about making functions a dictionary of lists). One reason that the documentation is more up to date in the example file is that it tracks the relevant version. As opposed to the book, where one doesn't want to change the docs until the changes make it to stable.
Re: [web2py] default function in a non default controller with args - routing
On 9 Jul 2012, at 1:29 PM, Francisco Costa wrote: I'm using the Parameter-based system for routing In my routes.py I have this routers = dict( # base router BASE = dict( applications = ['admin', 'app', 'blog'], default_application = 'app', map_hyphen = True, domains = { 'blog.domain.com' : 'blog', 'domain.com' : 'app' }, ), app = dict( controllers = ['default', 'user'], functions = ['index', 'show', 'list'], default_controller = 'default', default_function = dict(default='index', user='show') ), blog = dict( default_controller = 'default', ), ) When I go to http://localhost/user/john i get this: invalid function (user/john) I would like it to map it to http://localhost/user/show/john So it is possible to pass args to a default function in a non default controller without the name of the function? Try specifying functions as a dict of lists keyed by controller names, and include and entry for user. Something like app = dict( ... functions = dict( default = [ list of functions], user = [ list of functions ], ). ... One other thing to pay attention to is that by default there's a function app/default/user that manages your auth object. The router will do the right thing, but there may be some omissions that it won't be able to do because the conflict creates an ambiguity. In particular, the router can normally shorten /app/default/user/whatever to /user/whatever, but it can't do that if you have a function named user. You can work around that by renaming your controller, or by renaming the auth-support function and telling Auth: auth = Auth(... function='somethingotherthanuser'...)