Restoring viewlets

How do you get a Plone theme to uninstall and restore viewlets to the usual way. That is the mystery ...

The symptoms

In a theme I recently built, I moved or hid several viewlets around for artistic effect. The problem didn't show itself until I uninstalled the theme. The viewlets stayed where they were. I fiddled with the code and (on the basis of a posting about a similar problem) used 'remove' and 'purge' attributes in the install profile. Great - now I had viewlets in two locations.

To be specific: my theme took the site-actions and global-section (tabs) out of the header and tucked them into the footer of the site. After deinstalling, they appeared in both locations.

Reinstalling showed the expected appearance for my theme. Re-deinstalling showed the messed up behaviour. Clearing caches, refreshing etc. etc. didn't fix it. Examining a theme that also moves viewlets (plonetheme.labs) didn't show any magic code that fixed the issue.

The problem

There is an ultimate and immediate cause involved. The ultimate cause is that despite the promise of Generic Setup, if you are moving viewlets, you have to provide an uninstallation profile and installation and uninstallation functions. The immediate cause is that paster generated Plone themes (paster create plone3theme) don't include these. If you create a theme via paster doing anything more than providing a style sheet and images, you'll probably have to provide these yourself for proper deinstallation.

The Solution

The Weblion pages below provide detailed examples. If you look at the version of plonetheme.labs in SVN (as of this date), it also provides these. The released version of plonetheme.p2 can serve as an example as well.

Notes

This is another example of a Plone 'dorky pants' solution, where the cure ends up just complicating things. My theme already has 10 XML configuration files within it (and a single line ZMCL slug for installation), yet this is not enough to get it to install a stylesheet and move around a few page components - it needs installer methods as well. Which makes you wonder what advantage this offers over an old-style Plone Product. It's also not obvious why an uninstallation profile needs to be provided. Surely by default it could reverse everything the install profile does.

Thanks to Thomas Massman and Tobias Schmidt for pointing out the shortcomings of paster-generated themes.