I had thought that I could rely on a controller class' default() method to handle most of my page rendering requirements, if I kept most of the content of the page in the database. This works well for most cases except for root objects,
i.e. /, /site (where /site is a controllers.Root class).
What I found is that if I added this snippet to my default() method:
if hasattr(self, args[0]):
return(getattr(self, args[0]).index(*args, **kwargs))
then the index() of the child controller.Root was called.
Here's an example:
class Site(controller.Root):
def index(self, *args, **kwargs):
return(self.default(*args, **kwargs))
def default(etc)
# same as Root
class Root(controller.Root):
site = Site()
@turbogears.expose(html="grimmlabs.templates.generic")
def default(self, *args, **kwargs):
if hasattr(self, args[0]):
return(getattr(self, args[0]).index(*args, **kwargs))
try:
page = Page.byName(args[0])
except sqlobject.SQLObjectNotFound:
return(self.notFound(args, kwargs))
return dict(Page=page,))
If I call /site without the hasattr() bit above, I get the right page, but it is in the context of the Root class, which for a few reasons is not what I need.
So: am I doing this right, or is there a more obvious way to make this work right (i.e. /site appears in context of the Site class)?
Or am I blathering?
--
"Things fall apart. The Center cannot hold."
- Life as a QA geek, in a nutshell.
Best,
Jeff

