Fix for 404 occuring when signing out during the creation of, for example,
authorTodd Larsen <tlarsen@google.com>
Sat, 22 Nov 2008 09:22:44 +0000
changeset 548 2ceb3b14349c
parent 547 be0de865ffc9
child 549 00a9ce3dc082
Fix for 404 occuring when signing out during the creation of, for example, a new Document. This patch makes sure that the request.path is not altered when requesting the create page (alteration of which caused the 404). This also results in the seeds now being remembered when being forced to log in. The editPost method now correctly switches to the edit path after a successful edit. Patch by: Lennard de Rijk
app/soc/views/models/base.py
--- a/app/soc/views/models/base.py	Sat Nov 22 09:08:29 2008 +0000
+++ b/app/soc/views/models/base.py	Sat Nov 22 09:22:44 2008 +0000
@@ -197,11 +197,6 @@
     for field in fields:
       empty_kwargs[field] = None
 
-    request.path = params['create_redirect']
-    request.path = helper.requests.replaceSuffix(request.path,
-                                                 old_suffix='edit',
-                                                 new_suffix='edit')
-
     if not kwargs:
       return self.edit(request, page_name=page_name, params=params,
                        **empty_kwargs)
@@ -266,7 +261,16 @@
     key_name, fields = self.collectCleanedFields(form)
 
     # get the old_suffix before editing
-    old_suffix = self._logic.getKeySuffix(entity)
+    if entity:
+      old_suffix = '%s%s' %('edit/', self._logic.getKeySuffix(entity))
+    else:
+      # retrieve the suffix appened to the create path
+      splitted_path = request.path.split('/create/',1)
+      if len(splitted_path) == 2 :
+        old_suffix = '%s%s' %('create/', splitted_path[1])
+      else:
+        # no suffix after the create in the request path
+        old_suffix = 'create'
 
     self._editPost(request, entity, fields)
 
@@ -280,12 +284,12 @@
       return http.HttpResponseRedirect('/')
 
     page_params = params['edit_params']
-    suffix = self._logic.getKeySuffix(entity)
+    new_suffix = '%s%s' %('edit/', self._logic.getKeySuffix(entity))
 
     # redirect to (possibly new) location of the entity
     # (causes 'Profile saved' message to be displayed)
     return helper.responses.redirectToChangedSuffix(
-        request, old_suffix, suffix,
+        request, old_suffix, new_suffix,
         params=page_params)
 
   def editGet(self, request, entity, context, seed, params):