Plone Archetypes redirection after creation
Redirecting to some URL directly after clicking on "Save" on custom edit template for Archetype content type
I was recently attacked by a Plone 3 site wielding a fruit; a banana to be exact.
Luckily I have watched Monty Python's excellent video on self-defense entitled "How to defend one self when attacked by someone wielding a fruit", thus I survived the ordeal to tell the tale (or blog about it in this case).
It wasn't that the Plone site was a particularly savage beast, a 800 pound banana wielding primate. It was actually a very timid site, with a couple of Archetype content types, 1 custom workflow and some skinning done on it.
Some of you might say I provoked it. What else could possibly cause such a puny Plone site to turn on its creator with such menace and such intend to cause grievous bodily harm by means of a banana?
Well let me tell you: All I did was ask it nicely to redirect to a listing view after the user entered details for a Archetype content type and clicked on "Save".
Really, that was it.
The next moment I was bombarded by custom templates and custom .metadata files in the skins/templates directory, actions and validators and redirect_to's and edit_macro's and metal macro's and slots and and and...
I went and asked the great Oracle (Google to the rest of the world) and I got example on example of how to customize view templates and add custom form buttons. Each time I tried something new the Plone site laughed at my attempts and battered me on the head with a yellow fruit. It would seem that "base_edit"'s .metadata was the alpha and omega, nothing could dispose of it, nothing else mattered.
And after much parrying and blocking and kicking and screaming I shot the plone site, true to the Monty Python way of dealing with a banana attack, and removed all the custom templates and form controllers and metadata files that had caused the attack in the first place, and started from scratch.
The REAL Final Solution was suggested to me by a colleague
The Final Solution:
For content type cactus_plant:
- Copy validate_integrity.cpy and validate_integrity.cpy.metadata to your skins/*_templates dir
- Insert before the last return statement in validate_integrity.cpy the following code:
context_type = getattr(context, 'portal_type', None) if context_type and context_type == 'cactus_plant': state.setNextAction('redirect_to:string:${portal_url}/@@my_view') return state.set(status='created')
And Voila!. You get redirected to a custom view after creation.







