Plone Archetypes redirection after creation
I've searched the internet for a while, but I haven't found anything useful ...
I want to do something as simple as redirecting the page to the list page (folder) after saving / creating the AT content type.
I already know that I need to use validate_integrity.cpy and write my redirect logic there, but the file won't run ...
So far, this is an example of my validate_integrity.cpy:
## Script (Python) "validate_integrity"
##title=Validate Integrity
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind state=state
##bind subpath=traverse_subpath
##parameters=
##
from Products.Archetypes import PloneMessageFactory as _
from Products.Archetypes.utils import addStatusMessage
request = context.REQUEST
errors = {}
errors = context.validate(REQUEST=request, errors=errors, data=1, metadata=0)
import pdb; pdb.set_trace()
if errors:
message = _(u'Please correct the indicated errors.')
addStatusMessage(request, message, type='error')
return state.set(status='failure', errors=errors)
else:
message = _(u'Changes saved.')
stat = 'created'
# Redirection after saving edition forms
redirects = {'Multifile': context.aq_parent.absolute_url_path() + '/multifile'}
import pdb; pdb.set_trace()
if context.portal_type in redirects:
redirect = 'redirect_to:string:${portal_url}' + redirects[context.portal_type]
state.setNextAction(redirect)
else:
stat = 'success'
addStatusMessage(request, message)
return state.set(status=stat)
Decision
I just needed to write the following update step:
from Acquisition import aq_inner, aq_parent
from Products.CMFCore.utils import getToolByName
def upgrade(tool):
portal = aq_parent(aq_inner(tool))
setup = portal.portal_setup
setup.runImportStepFromProfile('profile-my.addon:default', 'skins')
source to share
Your * .metadata file may be missing or have an action that is routed to a different location than you expect: http://docs.plone.org/old-reference-manuals/forms/using_cmfformcontroller.html
The default metadata for content_edit lives in Products / Archetypes / skins / archetypes / content_edit.cpy.metadata:
...
[actions]
action.success = traverse_to:string:validate_integrity
action.success_add_reference = redirect_to:python:object.REQUEST['last_referer']
action.failure = traverse_to_action:string:edit
action.next_schemata = traverse_to_action:string:edit
Does your action button mean "success"?
source to share