Question

The .is_folderish attribute is used in many places. For example when setting an object as the default view or when activating discussions on an object.

My first question is how to check is an object has that attribute set. I tried using the bin/instance debug with something like this:

>>> app.site.news.is_folderish
...
AttributeError: is_folderish

I imagine that I can't reach attributes on that way because app.site.news is a wrapper to the object that has that attribute.

My second question is how to add that attribute to a new Dexterity object. I suppose I can do it using the code below (but I can't test it before the my first question is resolved).

from zope import schema
from plone.dexterity.content import Item

class IHorse(form.Schema):
    ...

class Horse(Item):
    def __init__(self):
        super(Horse, self).__init__(id)
        is_folderish = False

But I'm not sure about how both classes could be linked.

Was it helpful?

Solution

You don't need to add is_folderish to your types; it is an index in the catalog, and Dexterity types already have the proper attribute for that index, isPrincipiaFolderish.

If you do need to add attributes to content types, you can either use an event subscriber or create a custom subclass of plone.dexterity.content.Item:

  • subscribers can listen for the IObjectCreatedEvent event:

    from zope.app.container.interfaces import IObjectAddedEvent
    
    @grok.subscribe(IYourDexterityType, IObjectCreatedEvent)
    def add_foo_attribute(obj, event):            
        obj.foo = 'baz'
    
  • custom content classes need to be registered in your type XML:

    from plone.dexterity.content import Item
    
    class MyItem(Item):
        """A custom content class"""
        ...
    

    then in your Dexterity FTI XML file, add a klass property:

    <property name="klass">my.package.myitem.MyItem</property>
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top