Hola, Jorge!
On Monday April 27, 2009 11:03:14 you wrote:
> Hey Gustavo,
>
> I was looking at the tg/render.py on Saturday as I have been working
> on render_json and I notice the following.
>
> <repoze.who identity (hidden, dict-like) at 168548076>
>
> >>> template_vars.request.identity
>
> <repoze.who identity (hidden, dict-like) at 168548076>
>
> >>> template_vars.tmpl_context.identity
>
> <repoze.who identity (hidden, dict-like) at 168548076>
>
> >>> template_vars.tg.identity
>
> <repoze.who identity (hidden, dict-like) at 168548076>
>
> one is being set in tg/render and the other in
> tg/controlers/decoratedcontroller (tg2.1), I assume the request one is
> set by r.w* which is the original
>
> tg/render.py: the current visitor's identity information
> tg/render.py: # this will be None if no identity
> tg/render.py: identity = request.environ.get('repoze.who.identity'),
> tg/controllers/decoratedcontroller.py: #if there is an
> identity, push it to the pylons template context
> tg/controllers/decoratedcontroller.py: tmpl_context.identity =
> req.environ.get('repoze.who.identity')
>
> on top of that I see in the quickstart that
> templates/turbogears/+package+/lib/base.py_tmpl:
> request.identity = request.environ.get('repoze.who.identity')
> templates/turbogears/+package+/lib/base.py_tmpl:
> tmpl_context.identity = request.identity
>
> So my question is multipart.
>
> - isn't the second line in base.py redundant?
I don't think so; I mean: Those two lines in base.py aren't redundant (the
first one is used in the controllers and the other in the template). But I do
think there's some redundancy, in the occurrences you mention in tg.*.
BTW, I was only aware of
"request.identity=request.environ.get('repoze.who.identity')" in
"+package+/lib/base.py_tmpl" (I think it was me). The other occurrences must
be introduced recently, because I can't remember about them.
> - if you remove the lines from base.py isn't it setting 2 Nones on the
> template_vars potentially causing errors in the form None.something()
> ?
Most likely, I think. I'd suggest to leave base.py as is, and remove the
redundant code in tg.*.
> - why do we need the base.html lines anyway? can't we do something in
> the repoze middleware that will do
> if request.environ.get('repoze.who.identity'):
> request.identity = request.environ.get('repoze.who.identity')
Unfortunately, no. :(
The request object used in PYlons/TG2 is an instance of webob.Request, but
when a middleware passes control to the next middleware or the downstream
application, it has to pass the WSGI environ as a dictionary.
> - which location is best? I don't really see a reason for identity in
> tmpl_context
I'd prefer to leave those definitions on base.py, because it makes more
explicit what is going on.
And I think sometimes it's handy to have the identity variables in the
template context.
> - please see my other email regarding the way tg.identity worked in
> TG1, perhaps we should delete both and build an instance of the
> bunch-like class in tg/render for easy templating code.
I like the idea of turning the repoze.who into a bunch-like object, but I'm
not sure if it should go in repoze.who by default.
> PS: I send you this privately because it may be an omission on your
> part if you are ok discussing this in public please forward it to the
> list.
Sure, it's alright. ;-)
Saludos!
--
Gustavo Narea <xri://=Gustavo>.
| Tech blog: =Gustavo/(+blog)/tech ~ About me: =Gustavo/about |
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" 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-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---