I created some "widgets" (for lack of a more descriptive name) using the
same pattern as the Auth object. When you call it, it returns a special
function that can respond to several different "sub-functions". This has
been tremendously handy but now I'm encountering a problem -- when I uses
this in my "default" controller it fails to parse its sub-function properly.
Here is the code, patterned after Auth:
def __call__(self):
from gluon.http import HTTP
request = current.request
ra = request.args
if not ra:
return self.widget()
if ra[0] in self.api:
return getattr(self, ra.pop(0))()
else:
raise HTTP(404)
The above code lives in a module, not a controller. The method
self.widget() just returns a dictionary that contains the html and so
forth, for building the presentation of the widget. The instance var
self.api contains a list of "sub-functions" that, when called, will return
something different than the widget() function. Usually this is some sort
of ajax function or other script-y thing that is called from the widget.
My problem lies in the request.args[]. When called from any controller but
my default, everything works perfectly. The calling URL looks something
like:
/big_app/default/widget/sub_function/whatever
The request.args has the pieces: [sub_function,whatever] when I debug. All
is well.
Now I enable routes.py:
routers = dict(
BASE = dict(
applications = ['big_app','admin'],
default_application = 'big_app',
default_controller = 'default',
),
big_app = dict(
functions = ['index',...,'sub_function']
),
admin = dict(
)
)
After enabling the routes, my special function fails to work. In the code,
I can see that request.args is empty, even though it should show the
sub-function just as it did when not in the default controller.
My theory is that something in the act of hiding the default controller is
mucking with the parsing of the url.
But here's the mindblower... If the problem is url parsing with routes.py
then *why does Auth continue to work fine??* It's ALSO in default, and I
patterned my code after the same approach. I think this is like the
bumblebee that doesn't know it has been proven unable to fly by science,
and thusly goes ahead and files anyway.
Joe
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.