Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for Plone control panels

I'm working on a package that includes a control panel created using plone.app.registry. I followed Timo's tutorial but, when trying to add an additional record to it, I'm facing the infamous KeyError: a field for which there is no record.

So I have a couple of questions about best practices:

My first question is: a package must remove it's registry at uninstall time?

I used this in registry.xml of my package:

<registry>
  <records interface="collective.nitf.controlpanel.INITFSettings" />
</registry>

and this on metadata.xml:

<metadata>
  <version>1</version>
  <dependencies>
    <dependency>profile-plone.app.registry:default</dependency>
  </dependencies>
</metadata>

But adding a delete="true" on the uninstall profile seems not to be working. I tried also by listing all records by name with no luck, unless I run the step manually at ZMI.

So, my second question is: how do I remove control panel records at uninstall time gracefully?

To test if a record is on the registry I do something like this:

def setUp(self):
    self.portal = self.layer['portal']
    setRoles(self.portal, TEST_USER_ID, ['Manager'])
    # Set up the NITF settings registry
    self.registry = Registry()
    self.registry.registerInterface(INITFSettings)

def test_record_sections(self):
    # Test that the sections record is in the control panel
    record_sections = self.registry.records[
        'collective.nitf.controlpanel.INITFSettings.sections']
    self.failUnless('sections' in INITFSettings)
    self.assertEquals(record_sections.value, set([]))

A third question could be how to test if a record was removed at unisntall time.

Any other recommendation?

like image 281
hvelarde Avatar asked Aug 11 '11 18:08

hvelarde


2 Answers

Note: I have not used plone.app.registry myself directly in a package yet.

My first question is: a package must remove it's registry at uninstall time?

Yes. It at least seems reasonable to expect this from authors of community packages. I would hope that plone.app.registry does not trip over missing stuff from old removed packages, like it seems to be doing here, but that may be tricky.

So, my second question is: how do I remove control panel records at uninstall time gracefully?

In most GenericSetup files remove="True" works. Not sure about this specific case.

like image 98
maurits Avatar answered Sep 22 '22 22:09

maurits


My first question is: a package must remove it's registry at uninstall time?

I'm not part of remove things on uninstall time because some time you don't want to lose your configuration at re install... providing a way to cleanup the registry should be better for administrator of the site. Do test on a test instance where you don't care to lost your data.

The second question is already answered by maurits, so you should care about typo:

delete="true" != "remove="True"

like image 34
toutpt Avatar answered Sep 23 '22 22:09

toutpt