Author: eallen
Date: 2008-08-19 12:40:10 -0400 (Tue, 19 Aug 2008)
New Revision: 2321
Modified:
mgmt/trunk/cumin/python/wooly/__init__.py
mgmt/trunk/cumin/python/wooly/forms.py
mgmt/trunk/cumin/python/wooly/server.py
Log:
Save the http_referer (origin) so forms can easily return to it
Modified: mgmt/trunk/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/trunk/cumin/python/wooly/__init__.py 2008-08-19 14:50:32 UTC (rev 2320)
+++ mgmt/trunk/cumin/python/wooly/__init__.py 2008-08-19 16:40:10 UTC (rev 2321)
@@ -467,6 +467,7 @@
self.page = None
self.values = dict()
self.credentials = dict()
+ self.origin = None
if self.app.debug:
self.debug = self.Debug(self)
@@ -612,6 +613,12 @@
except ValueError:
pass
+ def set_origin(self, origin):
+ self.origin = origin
+
+ def get_origin(self):
+ return self.origin
+
def __repr__(self):
return "%s(trunk=%s,app=%s)" % \
(self.__class__.__name__, self.trunk, self.app)
Modified: mgmt/trunk/cumin/python/wooly/forms.py
===================================================================
--- mgmt/trunk/cumin/python/wooly/forms.py 2008-08-19 14:50:32 UTC (rev 2320)
+++ mgmt/trunk/cumin/python/wooly/forms.py 2008-08-19 16:40:10 UTC (rev 2321)
@@ -11,12 +11,34 @@
self.form_params = set()
+ self.origin = Parameter(app, "origin")
+ self.add_parameter(self.origin)
+
+ def get_origin(self, session):
+ origin = self.origin.get(session)
+
+ # this will happen if we load the page
+ # directly from a saved url and not through
+ # a link on another page
+ if not origin:
+ try:
+ branch = session.branch()
+ self.frame.show_view(branch)
+ origin = branch.marshal()
+ except: # we don't have a show_view
+ pass
+
+ return origin
+
def add_form_parameter(self, param):
self.form_params.add(param)
def render_hidden_inputs(self, session, *args):
writer = Writer()
+ # remember our roots
+ if not self.origin.get(session):
+ self.origin.set(session, session.get_origin())
params = set(session.get_page().get_saved_parameters(session))
params.difference_update(self.form_params)
Modified: mgmt/trunk/cumin/python/wooly/server.py
===================================================================
--- mgmt/trunk/cumin/python/wooly/server.py 2008-08-19 14:50:32 UTC (rev 2320)
+++ mgmt/trunk/cumin/python/wooly/server.py 2008-08-19 16:40:10 UTC (rev 2321)
@@ -35,6 +35,8 @@
session = Session(self.app)
session.unmarshal_page(env["PATH_INFO"])
session.unmarshal_url_vars(env["QUERY_STRING"])
+ if "HTTP_REFERER" in env:
+ session.set_origin(env["HTTP_REFERER"])
if "HTTP_AUTHORIZATION" in env:
auth = env["HTTP_AUTHORIZATION"].split(" ")[1]
Show replies by date