Hi Alice,
Alice Zoë Bevan–McGregor wrote:
> Is there anything preventing you from using a common superclass?
>
> E.g.
>
> class Foo(object):
> def __init__(self):
> # Perform your startup actions here, initializing web.ctx
> variables from web.conf ones, etc.
> # You have full access to the controller instance at this
> point through `self`.
>
> class MyController(Foo):
> def GET(self):
> pass
>
> def POT(self):
> pass
No, in fact that is one of the things I'm doing currently. It surely
prevents me from repeating the same instantiating code over and over
again. But as far as I can see it doesn't change the fact that the
handler creates its collaborators itself, meaning I can only have one
and the same set of collaborators during testing and during production.
I've actually done something like that:
class BaseHandler(object):
def __init__(self, testdb=None):
self.db = testdb or somemodule.get_production_db()
class Handler(BaseHandler):
def GET(...):
data = self.db....
which works around this fact. But I thought there might be just some
better way to do it. That's why I asked for your ideas :)
Thanks,
Ole.
--
Ole Trenner
<[email protected]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---