component .load

35 views
Skip to first unread message

mattynoce

unread,
Dec 29, 2010, 6:25:36 PM12/29/10
to web2py-users
hi all. i have a component i'm plugging into the middle of a page, but
i want that component to act seamlessly with the rest of the page. i
do NOT want the component to do what components usually do and act
independently. i need to include variable files, and components are
the only way i can find to do that.

so when i submit forms from the component, they automatically
append .load to redirects. i do not want this. so i found i can do:
redirect(URL(..., extension=''))

however, when i execute other commands like this:
def formControllerFromComponent:
doSomething()
doSomethingElse()
redirect(URL(..., extension=''))

doSomething() will create any links it makes with a .load extension. i
don't want to have to go around and append extension='' to every URL
command in my controller. is there a way we can stop propagation of
the .load suffix? based on a variable in the load initialization?
something like:
{{=LOAD(c='default', f='func', args=[arg1, arg2], ajax=False,
ajax_trap=False, loadPropagate=False)}}

thanks,

matt

Jonathan Lundell

unread,
Dec 29, 2010, 6:39:37 PM12/29/10
to web...@googlegroups.com

URL is probably picking up the .load extension from request.extension. It might be more convenient to set that to 'html'.

Jonathan Lundell

unread,
Dec 30, 2010, 12:30:05 PM12/30/10
to web...@googlegroups.com
On Dec 29, 2010, at 3:25 PM, mattynoce wrote:
>

This is a slightly tricky "feature". The propagation of the .load extension (or any extension) depends on how URL() is called. I think it's a problem in the way _gURL was implemented, and it makes URL even more hard to understand than it already was.

The issue is that URL defaults to request.extension (among other things) if request is passed to URL. And request is implicitly passed to URL if you call URL(func) or URL(ctlr, func) -- but *not* if you call URL(app, ctlr, func). And of course you can override extension with extension=something (as long as 'something' isn't None).

We don't ordinarily care about this propagation, because 'html', the default, is almost always what we want.

URL is already so tricky in the way it works that I'd be really wary of changing it; it'd almost certainly break something for someone. I haven't used LOAD, and I'm a little hazy on how it works, but perhaps we could change some central load handler to set request.extension=None, or something like that. I think that'd be reasonable, since a new load request would set the extension explicitly.

mattynoce

unread,
Dec 30, 2010, 12:49:52 PM12/30/10
to web2py-users
if i can override request.extension and have it propagate, that's
totally fine. if, for example, i could do this:

def formControllerFromComponent:
# *** new line ***
request.extension = 'html'

doSomething()
doSomethingElse()
redirect(URL(..., extension=''))

and have that stick as i bounce from function to function, that's
absolutely what i need. i don't need it to be handled by a central
handler so long as i know what the process is. it's simply a matter of
knowing how to affect the necessary change.

i already changed my code to work on a redirect so i'd get around the
extension piece, but if this will work in concept, i'll go back to
using it in the future.

thanks,

matt

Jonathan Lundell

unread,
Dec 30, 2010, 12:59:14 PM12/30/10
to web...@googlegroups.com
On Dec 30, 2010, at 9:49 AM, mattynoce wrote:
>
> if i can override request.extension and have it propagate, that's
> totally fine. if, for example, i could do this:
>
> def formControllerFromComponent:
> # *** new line ***
> request.extension = 'html'
>
> doSomething()
> doSomethingElse()
> redirect(URL(..., extension=''))
>
> and have that stick as i bounce from function to function, that's
> absolutely what i need. i don't need it to be handled by a central
> handler so long as i know what the process is. it's simply a matter of
> knowing how to affect the necessary change.
>
> i already changed my code to work on a redirect so i'd get around the
> extension piece, but if this will work in concept, i'll go back to
> using it in the future.

That'll work, and you don't have to set extension= in the redirect. Also, you can set request.extension = None, which sets things back to their default state (effectively).

I'm not sure how formControllerFromComponent figures in your flow. In general, you can set request.extension = None in any .load controller to avoid propagation.

mattynoce

unread,
Dec 30, 2010, 1:09:00 PM12/30/10
to web2py-users
perfect. mission accomplished.

re: your comment, formControllerFromComponent is the return function
from a non-ajax component form. the main controller function loads the
component, the component shows a form, and the form action is
formControllerFromComponent.

now i'll just set request.extension inside that function and
everything should work as i was hoping.

much obliged.
Reply all
Reply to author
Forward
0 new messages