Thanks in advance for any help. My problem is getting context to remember things. If I remember something when the context is PageContext, I cannot retrieve it when the context changes to say WebContext because it tells me that it has not been remembered. Now, I was under the impression that context would search for my interface through the different contexts but this does not seem to be the case. This kind of limits what I can do with context because I have no idea when the context changes and my rememberances will be forgotten. Example Problem def render_cow(self, ctx, data): ctx.remember(data, ISomeInterface) def render_something_else(self, ctx, data): mydata = ctx.locate(ISomeInterface) Now in between remebering ISomeInterface and recalling it the context changes and it is no longer remebered. My apologies if I am way out with my understanding and any help is appreciated. Thanks Michael
Michael M wrote:
Thanks in advance for any help.
My problem is getting context to remember things. If I remember something when the context is PageContext, I cannot retrieve it when the context changes to say WebContext because it tells me that it has not been remembered.
Now, I was under the impression that context would search for my interface through the different contexts but this does not seem to be the case. This kind of limits what I can do with context because I have no idea when the context changes and my rememberances will be forgotten.
Example Problem
def render_cow(self, ctx, data): ctx.remember(data, ISomeInterface)
def render_something_else(self, ctx, data): mydata = ctx.locate(ISomeInterface)
Now in between remebering ISomeInterface and recalling it the context changes and it is no longer remebered.
My apologies if I am way out with my understanding and any help is appreciated.
If your template is <foo n:render="cow"> <bar n:render="something_else /> </foo> that should work. If your template is <foo n:render="cow" /> <bar n:render="something_else /> then it even shouldn't work (AIUI). The context stack in the latter example is like this, as time passes: [the page] ... [the page] [context for render_cow] ... [the page] ... [the page] [context for render_something_else]
Its been pointed out to me that some of my messages have not been going to the list so I will post a summary of what I have learnt so far thanks to Tommi. I was under the impression that with context it would be possible to remember an interface by doing ctx.remember(data, ISomeInterface) and then recall this interface anywhere throughout the request. This does not work as I expected and the reason for this is that context changes throughout the request and so looses what it has remembered when it changes. Example: def render_cow(self, ctx, data): """Context is say WovenContext""" ctx.remember('myinfo', ISomeInterface) def render_dog(self, ctx, data): """Context is now PageContext""" myinfo = ctx.locate(ISomeInterface) This will fail because I remembered data when the context was WovenContext and now the context is PageContext and so it does not have the data and interface that I remembered. Now I didn't think that this would be a problem because I thought that the context stack?? would be searched, i,e PageContext is searched for ISomeInterface, then maybe WovenContext is searched etc until the interface is found. Obviously this is not quite right. Tommi stated that: "Nested in template does not mean nested in implementation." and "remember the thing you want on something that stays on the stack for the duration you want."
From this I gather that some interfaces stay on the context stack longer than others?
So I need to investigate the following. 1.) How do I find out what interfaces stays on the stack for the duration of the whole request? 2.) If I remebered say ctx.remember('myinfo', IRequest)...will this mean I cannot use IRequest to retrieve the request, i.e I will have overwritten request. 3.) How to I make my own interfaces stay on the stack throughout the request. Off to read some more nevow code and do some tests and I will post back to the list the results so hopefully some other users benefit. Cheers Michael
participants (2)
-
Michael M
-
Tommi Virtanen