[web2py] Re: default function of a controller
On Friday, August 5, 2011 6:26:04 AM UTC-4, Francisco Costa wrote: > > > > On Aug 5, 12:54 am, pbreit wrote: > > That should be easy to support. In default.py: > > > > def user(): > > if request.args(0): > > user = request.args(0) > > ... > > else: # list > > ... > > > > def restaurant(): > > if request.args(0): > > restaurant = request.args(0) > > ... > > else: # list > > ... > > and if you have them in different controllers? > I think that you should be able to define different default functions > for each controller in web2py > That would be a nice addition, but if the purpose of defining a default function is to hide it in the URL, then you can just use the same default function name in each controller -- since the name won't appear in the URL anyway, it's not too important what it is (from the end-user perspective). In your case, can't you just set the default function to 'view' (the function you want to hide is called 'view' in both controllers)? Or set it to 'index', but move the 'view' functionality to the 'index' function, and then rename the current 'index' function to something else, such as 'list'. Anthony
[web2py] Re: default function of a controller
Then this should work: === user.py === def index() if request.args(0): user = request.args(0) ... else: # list ... === restuarant.py === def index() if request.args(0): user = request.args(0) ... else: # list ...
[web2py] Re: default function of a controller
On Aug 5, 12:54 am, pbreit wrote: > That should be easy to support. In default.py: > > def user(): > if request.args(0): > user = request.args(0) > ... > else: # list > ... > > def restaurant(): > if request.args(0): > restaurant = request.args(0) > ... > else: # list > ... and if you have them in different controllers? I think that you should be able to define different default functions for each controller in web2py
[web2py] Re: default function of a controller
That should be easy to support. In default.py: def user(): if request.args(0): user = request.args(0) ... else: # list ... def restaurant(): if request.args(0): restaurant = request.args(0) ... else: # list ...
[web2py] Re: default function of a controller
I have controller over my URLs I have this controller 'user' with 2 functions: index(list of users), view(user details) I have another controller 'restaurant' with 2 functions: index(list of restaurants), view(restaurant details) I wanted to have this urls: http://domain.com/user/mcdonalds and http://domain.com/restaurant/mcdonalds On Jul 12, 10:35 pm, pbreit wrote: > How do you want it to work exactly? Can you show us an example? And what are > your constraints? Do you not have control over your URLs?
[web2py] Re: default function of a controller
How do you want it to work exactly? Can you show us an example? And what are your constraints? Do you not have control over your URLs?
[web2py] Re: default function of a controller
If your controller doesn't have an index function at all, you could add something like this to one of your models: if request.controller = 'mycontroller' and request.function == 'index': request.function = 'myfunction' So that if someone tries to go to /mycontroller or /mycontroller/index, they will get the 'myfunction' function instead.
[web2py] Re: default function of a controller
On Jun 14, 7:57 pm, Jonathan Lundell wrote: > On Jun 14, 2011, at 11:42 AM, Francisco Costa wrote: > > > > >> You can only do this for the default controller. You do it by specifying a > >> list of the functions in the default controller: functions = [...]. > > > I have that for the default controller, but in this case I need to > > have it in a non-default controller > > > It's not possible to have this feature? > > It's not supported. If someone wants to implement it, I suggest allowing: > functions = dict(...) (in addition to a list), where each dict entry would be > of the form: controllername = [list of functions]. Be sure to write a set of > unit tests. Any update on this one?
Re: [web2py] Re: default function of a controller
On Jun 14, 2011, at 11:42 AM, Francisco Costa wrote: > >> You can only do this for the default controller. You do it by specifying a >> list of the functions in the default controller: functions = [...]. > > I have that for the default controller, but in this case I need to > have it in a non-default controller > > It's not possible to have this feature? It's not supported. If someone wants to implement it, I suggest allowing: functions = dict(...) (in addition to a list), where each dict entry would be of the form: controllername = [list of functions]. Be sure to write a set of unit tests.
[web2py] Re: default function of a controller
> You can only do this for the default controller. You do it by specifying a > list of the functions in the default controller: functions = [...]. I have that for the default controller, but in this case I need to have it in a non-default controller It's not possible to have this feature?
Re: [web2py] Re: default function of a controller
On Jun 14, 2011, at 11:28 AM, Francisco Costa wrote: > >> Well, it does support matching the host name, so I suppose it should be >> doable. > > And in the Parameter-Based System how do you bypass a function in the > url > > Something like this: http://domain.com/app/controller/arg1/ You can only do this for the default controller. You do it by specifying a list of the functions in the default controller: functions = [...].
[web2py] Re: default function of a controller
> Well, it does support matching the host name, so I suppose it should be > doable. And in the Parameter-Based System how do you bypass a function in the url Something like this: http://domain.com/app/controller/arg1/
[web2py] Re: default function of a controller
On Tuesday, June 14, 2011 2:13:38 PM UTC-4, mwolfe02 wrote: > > Someone please correct me if I'm wrong, but I believe the Pattern- > Based System supports URL re-writing different domains to different > applications. Well, it does support matching the host name, so I suppose it should be doable.
[web2py] Re: default function of a controller
Someone please correct me if I'm wrong, but I believe the Pattern- Based System supports URL re-writing different domains to different applications. On Jun 14, 1:56 pm, Francisco Costa wrote: > > If you use the parameter-based URL rewrite system > > (seehttp://web2py.com/book/default/chapter/04#Parameter-Based-System), you > > can > > specify default_function in either the BASE router or an application > > specific router, but I think that would set the default function for all > > controllers, not just a particular controller. Otherwise, I suppose you > > could use the pattern-based rewrite system > > (seehttp://web2py.com/book/default/chapter/04#Pattern-Based-System). Note, > > the > > two systems cannot be mixed. > > I must use the Parameter-Based System because I have different domains > linking to different applications.. > I think that being able to choose a default function for each > controller would be a top-feature!
[web2py] Re: default function of a controller
> If you use the parameter-based URL rewrite system > (seehttp://web2py.com/book/default/chapter/04#Parameter-Based-System), you can > specify default_function in either the BASE router or an application > specific router, but I think that would set the default function for all > controllers, not just a particular controller. Otherwise, I suppose you > could use the pattern-based rewrite system > (seehttp://web2py.com/book/default/chapter/04#Pattern-Based-System). Note, the > two systems cannot be mixed. I must use the Parameter-Based System because I have different domains linking to different applications.. I think that being able to choose a default function for each controller would be a top-feature!
[web2py] Re: default function of a controller
> Actually, redirect takes a URL, so you can pass the args to the URL > function: > > redirect(URL('other_controller', 'other_function', args=request.args, > vars=request.vars)) I didn't know that > I'm not sure I would recommend the redirect method, though -- it generates a > new request, so introduces an unnecessary delay. It also returns a 303 HTTP > status code by default (though you can change that to 200 via a second > argument to redirect). I also didn't want to use that solution, because I'm trying to have clean urls. With that solution I get the function name in the url :/
[web2py] Re: default function of a controller
On Tuesday, June 14, 2011 1:32:36 PM UTC-4, Francisco Costa wrote: > > > But why change this? I always advise not changing this. One thing you > could > > do instead is: > > > > def index(): > > redirect('other_controller', 'other_function') > > That solution doesn't work for me because I have some arguments. > Is there another way? I use the new routers function on routes.py Actually, redirect takes a URL, so you can pass the args to the URL function: redirect(URL('other_controller', 'other_function', args=request.args, vars=request.vars)) I'm not sure I would recommend the redirect method, though -- it generates a new request, so introduces an unnecessary delay. It also returns a 303 HTTP status code by default (though you can change that to 200 via a second argument to redirect). Anthony
[web2py] Re: default function of a controller
On Jun 14, 6:25 pm, pbreit wrote: > You can set default_controller and default_function in routes.py but that > changes it for your whole app. Yes, I have index as the default function but for a specific controller I want it to be a different default function. > But why change this? I always advise not changing this. One thing you could > do instead is: > > def index(): > redirect('other_controller', 'other_function') That solution doesn't work for me because I have some arguments. Is there another way? I use the new routers function on routes.py
[web2py] Re: default function of a controller
On Tuesday, June 14, 2011 6:55:11 AM UTC-4, Francisco Costa wrote: > > Hello, > > I have this controller (not the default one) that I would like to have > a default function (not index) > > How can I do that? If you use the parameter-based URL rewrite system (see http://web2py.com/book/default/chapter/04#Parameter-Based-System), you can specify default_function in either the BASE router or an application specific router, but I think that would set the default function for all controllers, not just a particular controller. Otherwise, I suppose you could use the pattern-based rewrite system (see http://web2py.com/book/default/chapter/04#Pattern-Based-System). Note, the two systems cannot be mixed. Anthony
[web2py] Re: default function of a controller
You can set default_controller and default_function in routes.py but that changes it for your whole app. But why change this? I always advise not changing this. One thing you could do instead is: def index(): redirect('other_controller', 'other_function')
[web2py] Re: default function of a controller
I also want to know that.. its in the routes?? On Jun 14, 11:55 am, Francisco Costa wrote: > Hello, > > I have this controller (not the default one) that I would like to have > a default function (not index) > > How can I do that?
[web2py] Re: default function of a controller
is this possible? On Jun 14, 11:55 am, Francisco Costa wrote: > Hello, > > I have thiscontroller(not thedefaultone) that I would like to have > adefaultfunction(not index) > > How can I do that?