Never mind. I just figured out that 
from tg import request

instead of 

from webob import Request as request

yields the expected result.
(might be nice to have a little mention of that in the docs though)

Uwe


On Thursday 28 May 2009, Uwe C. Schroeder wrote:
> The docs say to
>
> from webob import Request
>
> and then one can do stuff like
>
> Request.user_agent
>
> which should return a string.
> But hey, the request isn't initialized, so looking at the code of webobj:
>
>     def __get__(self, obj, type=None):
>         if obj is None:
>             return self
>         if self.key not in obj.environ:
>             if self.default_factory:
>                 val = obj.environ[self.key] = self.default_factory()
>                 return val
>             else:
>                 return self.default
>         return obj.environ[self.key]
>
> I get the "obj is None" version as the result of Request.user_agent - it is
> a environ_getter object but no string.
>
> Ok, I'm not doing this in the controller, I'm doing this in helpers.py in
> the lib directory. What I need is a method to test for the user agent which
> is available in all templates (just like stdvars.py used to do in TG1). Is
> helpers.py loaded statically and not per request? If so, how can I have a
> method in every template and where do I initialize it (BTW: the TG2 docs
> don't talk about this at all, at least not that I could find it)
>
> Any pointers as usual greatly appreciated.
>
> Uwe
>
>
> 


-- 
        UC

--
Open Source Solutions 4U, LLC   1618 Kelly St
Phone:  +1 707 568 3056         Santa Rosa, CA 95401
Cell:   +1 650 302 2405         United States
Fax:    +1 707 568 6416

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to