Fixes the problem of <Entity> Saved not being
authorLennard de Rijk <ljvderijk@gmail.com>
Tue, 17 Feb 2009 17:28:54 +0000
changeset 1373 178bd19966fe
parent 1372 a9b7f64d4813
child 1374 ed12ed835755
Fixes the problem of <Entity> Saved not being shown whenever a new entity is created. Patch by: Madhusudan C.S. Reviewed by: Lennard de Rijk
app/soc/views/helper/requests.py
app/soc/views/models/base.py
--- a/app/soc/views/helper/requests.py	Tue Feb 17 16:37:24 2009 +0000
+++ b/app/soc/views/helper/requests.py	Tue Feb 17 17:28:54 2009 +0000
@@ -22,6 +22,7 @@
   ]
 
 
+import os
 import urlparse
 
 
@@ -91,7 +92,7 @@
 
 
 def isReferrerSelf(request,
-                   expected_prefix=None, suffix=None):
+                   expected_prefix=None, suffix=None, url_name=None):
   """Returns True if HTTP referrer path starts with the HTTP request path.
     
   Args:
@@ -103,6 +104,7 @@
       it to the HTTP referrer path in the HTTP request object headers
       (this is often an link ID, for example, that may be changing from
       a POST referrer to a GET redirect target) 
+    url_name: url name of the entity that is being created
   
   Returns:
     True if HTTP referrer path begins with the HTTP request path (either
@@ -112,13 +114,18 @@
        
   """
   http_from = request.META.get('HTTP_REFERER')
-      
+
   if not http_from:
     # no HTTP referrer, so cannot possibly start with expected prefix
     return False
 
+  http_host = 'http://%s/%s' %(os.environ['HTTP_HOST'],url_name)
+
+  if http_from.startswith(http_host):
+    return True
+
   from_path = urlparse.urlparse(http_from).path
-  
+
   if not expected_prefix:
     # use HTTP request path, since expected_prefix was not supplied
     expected_prefix = request.path
@@ -135,7 +142,7 @@
   if not from_path.startswith(expected_prefix):
     # expected prefix did not match first part of HTTP referrer path
     return False
- 
+
   # HTTP referrer started with (possibly truncated) expected prefix
   return True
 
--- a/app/soc/views/models/base.py	Tue Feb 17 16:37:24 2009 +0000
+++ b/app/soc/views/models/base.py	Tue Feb 17 17:28:54 2009 +0000
@@ -412,15 +412,17 @@
 
     suffix = self._logic.getKeySuffix(entity)
 
-    # Remove the params from the request, this is relevant only if
+    # remove the params from the request, this is relevant only if
     # someone bookmarked a POST page.
-    is_self_referrer = helper.requests.isReferrerSelf(request, suffix=suffix)
+    is_self_referrer = helper.requests.isReferrerSelf(
+        request, suffix=suffix, url_name=params['url_name'])
+
     if request.GET.get(params['submit_msg_param_name']):
       if (not entity) or (not is_self_referrer):
         return http.HttpResponseRedirect(request.path)
 
     if entity:
-      # Note: no message will be displayed if parameter is not present
+      # note: no message will be displayed if parameter is not present
       context['notice'] = helper.requests.getSingleIndexedParamValue(
           request, params['submit_msg_param_name'],
           values=params['save_message'])