[Twisted-web] [PATCH] Are we ready for a Page.remember fix?

Alex Levy mesozoic at polynode.com
Mon Nov 22 11:00:10 MST 2004


This was suggested a long time ago, and when I tried adding it, I broke
Quotient somewhat badly. From what I can tell, the problem in Quotient which
prevented Page.remember from being changed has been fixed; I'd like to see
this patch added.

Some have suggested a SiteContext as an alternative; however, I see these
two as addressing two different concerns. A SiteContext (as described in
Roundup <http://divmod.org/users/roundup.twistd/nevow/issue137>) would be
good for remembering data that are universal to a specific NevowSite
instance. However, this is not my use case.

In my case, I want my Realm to be able to remember objects that are
particular to a certain logged in user. The obvious example is an
ICurrentUser interface, which lets the resource hierarchy quickly reference
what user (if any) is logged in. I'm sure I'll come up with other uses, but
this is my current need. Doing this at the SiteContext level would (from
what I can tell) produce overlaps when more than one user is logged in.

So, are there any objections to Page.remember()? Even if it's not an elegant
solution, it works for me, and it's generic enough that I think it's worth
keeping.

-- 
Alex Levy
WWW: http://mesozoic.geecs.org/
 
"Never let your sense of morals prevent you from doing what is right."
 -- Salvor Hardin, Isaac Asimov's _Foundation_
-------------- next part --------------
Index: nevow/rend.py
===================================================================
--- nevow/rend.py       (revision 847)
+++ nevow/rend.py       (working copy)
@@ -247,7 +247,8 @@

     docFactory = None
     original = None
-
+    toremember = None
+
     def __init__(self, original=None, docFactory=None):
         if original is not None:
             self.original = original
@@ -289,16 +290,7 @@
         XXX THIS IS DEPRECATED. The page context is now passed to various
         Page apis. Remember things there instead.
         """
-        import sys
-        frame = sys._getframe()
-        done = False
-        while not done:
-            for ctx in frame.f_locals.values():
-                if isinstance(ctx, PageContext):
-                    done=True
-                    break
-            frame = frame.f_back
-        ctx.remember(obj, inter)
+        self.toremember.append((obj, inter))

     def rememberStuff(self, ctx):
         ctx.remember(self, inevow.IRenderer)
Index: nevow/context.py
===================================================================
--- nevow/context.py    (revision 847)
+++ nevow/context.py    (working copy)
@@ -235,9 +235,14 @@
     IRendererFactory
     IData
     """
-    context = property(getRequestContext)

+    def __init__(self, *args, **kw):
+        FactoryContext.__init__(self, *args, **kw)
+        if self.tag is not None and hasattr(self.tag, 'toremember'):
+            for i in self.tag.toremember:
+                self.remember(*i)

+    context = property(getRequestContext)

 # TTT: To stay here.
 NodeNotFound = stan.NodeNotFound # XXX: DeprecationWarning?



More information about the Twisted-web mailing list