Proper fallback from referer to REQUEST_URI
[cascardo/ipsilon.git] / ipsilon / util / page.py
index d2ccb51..7e88534 100644 (file)
@@ -16,7 +16,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import cherrypy
-from ipsilon.util.log import Log
+from ipsilon.util.endpoint import Endpoint
 from ipsilon.util.user import UserSession
 from ipsilon.util.trans import Transaction
 from urllib import unquote
@@ -40,8 +40,9 @@ def admin_protect(fn):
     return check
 
 
-class Page(Log):
+class Page(Endpoint):
     def __init__(self, site, form=False):
+        super(Page, self).__init__(site)
         if 'template_env' not in site:
             raise ValueError('Missing template environment')
         self._site = site
@@ -137,9 +138,17 @@ class Page(Log):
             # Try with kwargs first
             tid = t.find_tid(kwargs)
             if not tid:
-                # If no TID yet See if we have it in a referer
+                # If no TID yet See if we have it in a referer or in the
+                # environment in the REDIRECT_URL
+                url = None
                 if 'referer' in cherrypy.request.headers:
-                    r = urlparse(unquote(cherrypy.request.headers['referer']))
+                    url = cherrypy.request.headers['referer']
+                    r = urlparse(unquote(url))
+                    if r.query:
+                        tid = t.find_tid(parse_qs(r.query))
+                if not tid and 'REQUEST_URI' in cherrypy.request.wsgi_environ:
+                    url = cherrypy.request.wsgi_environ['REQUEST_URI']
+                    r = urlparse(unquote(url))
                     if r.query:
                         tid = t.find_tid(parse_qs(r.query))
                 if not tid: