Thank you! That works brilliant!

On 29 Aug., 19:18, Anand Chitipothu <[email protected]> wrote:
> 2010/8/29 Ole Trenner <[email protected]>:
>
>
>
> > Hi Tobias,
>
> > Am 28.08.2010 um 19:21 schrieb trx:
> >> Hello everyone,
>
> >> i like to suggest a little feature, which comes in pretty handy i
> >> think. I'd like to see a defaultarg argument in the web.application
> >> class. This variable is then passed to each page as the first
> >> argument.
> >> Example:
> >> [...]
> >> class Environment:
> >>    [...]
>
> >> class Index:
> >>    def GET(self, env):
> >>        return env.render_template(...) # for example
>
> >> env = Environment()
> >> app = web.application(URLS, globals(), defaultarg=env)
>
> > I've been proposing something like that myself [1]. At the time I did 
> > prefer constructor arguments over handler method arguments, but in the end 
> > they serve the same purpose. Anyway, I'm all in favor of something like 
> > this, so +1 from me.
>
> > Cheers,
> > Ole.
>
> > [1] 
> > <http://groups.google.com/group/webpy/browse_thread/thread/5a651b34dab...>
>
> I'm not sure, if I want to support that in web.py. But you can achieve
> that using the following code (warning: not tested).
>
> class myapplication(web.application):
>     def __init__(self, *a, **kw):
>         self.defaultargs = kw.pop('defaultargs', [])
>         web.application.__init__(self, *a, **kw)
>
>     def handle(self):
>         host = web.ctx.host.split(':')[0] #strip port
>         fn, args = self._match(self.mapping, host)
>         args = self.defaultargs + args or []
>         return self._delegate(fn, self.fvars, args)
>
> Anand

-- 
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.

Reply via email to