We have a browser view with a a list of links to other items (their @@edit view in particular. After clicking on the edit link and after saving/cancelling the edit form the browser should redirect to the original view (or a different URL specified somehow) instead of the @@view of the related context object...any idea how to solve this?
from Acquisition import aq_inner
from plone.dexterity.browser import add
from plone.dexterity.utils import addContentToContainer
class CruAddForm(add.DefaultAddForm):
portal_type = 'cru'
def add(self, object):
container = aq_inner(self.context)
addContentToContainer(container, object, checkConstraints=False) #you only need checkConstraints=False for anonymous add
self.immediate_view = container.absolute_url() #redirect here
class CruAddView(add.DefaultAddView):
form = CruAddForm
seems about right, but you also need to override the add method of add add.py if you want it to redirect to a different view on add as well as it doesn't seem to use nextURL to handle redirect.
The trick was to add a return_url=.... parameter to the related edit links and pick up the return_url parameter inside the nextURL() method from request/HTTP_REFERER.